Search code examples
symfonysymfony-3.1api-platform.com

Symfony 3 - Api-Platform - FatalErrorException in AddFormatListener.php line 131


I am using Api-Platform 2.0 in a Symfony 3.1.6 project.
I worked on my API, and when I came back to my project I had this error :
FatalErrorException in AddFormatListener.php line 131
Parse Error: syntax error, unexpected ':', expecting ';' or '{'
Here is the portion of code of that file :

private function getNotAcceptableHttpException(string $accept, array $mimeTypes = null): NotAcceptableHttpException
{
    if (null === $mimeTypes) {
        $mimeTypes = array_keys($this->mimeTypes);
    }

    return new NotAcceptableHttpException(sprintf(
        'Requested format "%s" is not supported. Supported MIME types are "%s".',
        $accept,
        implode('", "', $mimeTypes)
    ));
}

When I delete : NotAcceptableHttpExceptionthe error disapears but another come from another file in the api-platform folder.
. I tried to update my symfony project throught composer and the api-platform too but it didn't resolved anything. However I got a warning that might be interesting :

Trying to install assets as relative symbolic links.

            Bundle              Method / Error

  WARNING   ApiPlatformBundle   copy

However I don't understand either the meaning of this warning. Thanks


Solution

  • Got the same error, Api-Platform 2.0 requires php 7.0 Check if your web server is running the correct version of php

    To change php version with apache2 (my example was php 5.6 to 7.0 so) :

    sudo a2dismod php5.6
    sudo a2enmod php7.0
    sudo service apache2 restart
    

    If you are using a virtual host, check that it is using the right version of php fpm too