3

PLEASE READ BEFORE MARKED IT AS DUPLICATE, because I did not write the symphony code.

A syntax error was raised after I added the following library: composer require doctrine/dbal. This only happens on production and not on local env.

Im getting the following error:

Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) on symfony/translation/Translator.php79

This is my composer.json

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=7.0.0",
        "barryvdh/laravel-cors": "^0.11.0",
        "doctrine/dbal": "2.6.3",
        "fideloper/proxy": "~3.3",
        "guzzlehttp/guzzle": "^6.3",
        "laravel/framework": "5.5.*",
        "laravel/tinker": "~1.0"
    },
    "require-dev": {
        "filp/whoops": "~2.0",
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "~1.0",
        "phpunit/phpunit": "~6.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    }
}

And here it is my composer.lock:

https://gist.github.com/Jatapiaro/61eeb4136b38395224797928cf7bab04

I added it on a gist to avoid have lot of code here.

I guess it might be related to PHP version incompatibility, but I'm not sure about this.

Also, it's important to note that this syntax error was raised after a package install and it's not my code which got broken.

What could be going on?

PHP Version on local: 7.1.7. On the server is: PHP Version => 7.2.2-3+ubuntu16.04.1+deb.sury.org+1

One of the latest discovers is the following:

The line 79 of the symfony code is

 /**
     * @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;
    }

So when I changed ?string $locale to $locale everything works on production. It's important to add that also I change dbal to 2.6.3 because it causes conflicts with some queries.

Jacobo
  • 1,259
  • 2
  • 19
  • 43
  • Please @Machavity READ the question before mark it as a duplicate. – Jacobo Aug 05 '18 at 22:43
  • 1
    I think we should reopen this. The marked duplicate is inappropriate because the linked question addresses syntax errors in your own code. It's inappropriate to make edits to code in the vendor directory. [This question](https://stackoverflow.com/questions/48806424/symfony-parse-error-in-output-php-when-creating-project-in-laravel) looks similar, but is also an inappropriate duplicate because that question is using Laravel 5.6/PHP7.0 (a documented conflict). This question uses Laravel 5.5, which is consistent with the PHP requirements noted in the composer file. – HPierce Aug 05 '18 at 23:12
  • That said, @Jacobo, you should update the question to explicitly highlight your PHP version. I've voted to reopen this. – HPierce Aug 05 '18 at 23:14
  • @JacoboTapia this looks like this version of `doctrine/dbal` requires a more recent PHP version. As per HPierce notes, would you attach which PHP version do you have installed? – alariva Aug 05 '18 at 23:47
  • This question is not related to syntax error, but to package PHP version compatibility. The related dupe does not provide any clue on how to diagnose compatibility issues with vendor code. I think this should be reopen. – alariva Aug 06 '18 at 00:00
  • On local I have `7.1.7` and on production the version is: `PHP 7.2.2-3+ubuntu16.04.1+deb.sury.org+1`. Also the error thrown is on the method declaration. That I add, so when I removed that `?string` to `string` everything worked. Also dbal causes conflict with the queries so I returned it to `2.6.3` – Jacobo Aug 06 '18 at 00:16
  • 1
    I know what is the answer. But I can’t pos it. Anyway, The PHP CLI was using PHP 7.2, and also composer takes PHP 7.2 as the PHP version, so it doesn’t send any errors. When we open the website, the web takes the PHP version as 7.0. So in order to make apache to recognise the last version I did `$ sudo a2dismod php7.0 && $ sudo a2enmod php7.2 && $ service apache2 restart` – Jacobo Aug 06 '18 at 07:34
  • Don't be alarmed by the closed as duplicate. There is some troll going around closing questions at random. These things happen. Sooner or later they will get banned and life will go on. – Cerad Aug 06 '18 at 12:01

0 Answers0