Skip to content

Im getting the following error: Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) #28138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Jatapiaro opened this issue Aug 6, 2018 · 2 comments

Comments

@Jatapiaro
Copy link

Jatapiaro commented Aug 6, 2018

Symfony version(s) affected: Latest

Description
On production with PHP Version => 7.2.2-3+ubuntu16.04.1+deb.sury.org+1 I got the following error:
Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE)

How to reproduce
Just try to access any route on laravel. You need to include doctrine/dbal.

Possible Solution
The error throws the line 79 of the code.

 /**
     * @throws InvalidArgumentException If a locale contains invalid characters
     */
    public function __construct(?string $locale, MessageFormatterInterface $formatter = null, string $cacheDir = null, bool $debug = false)
    {
        $this->setLocale($locale);
 
        if (null === $formatter) {
            $formatter = new MessageFormatter();
        }
 
        $this->formatter = $formatter;
        $this->cacheDir = $cacheDir;
        $this->debug = $debug;
    }

That line corresponds to the method declaration, why does it have a ?string, I just removed that ? and everything works fine.

Also I have this stackoverflow issue if you need more information: https://stackoverflow.com/questions/51698746/how-to-fix-a-syntax-error-on-symfony-component-raised-after-composer-require-doc?noredirect=1#comment90359711_51698746

@kaznovac
Copy link
Contributor

kaznovac commented Aug 6, 2018

check your php version

@xabbuh
Copy link
Member

xabbuh commented Aug 6, 2018

This error message happens when your PHP version is below PHP 7.1 which introduced nullable type hints (see http://php.net/manual/en/migration71.new-features.php). When checking the PHP version, keep in mind that the version used on CLI can be different from the one used by the web server.

@xabbuh xabbuh closed this as completed Aug 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants