0

I have Laravel 5.4 installed on PHP 5.6.4 server, and i can't start the app. Everything works ok locally with the same configuration, but on the server i get this error:

(1/1) FatalErrorException syntax error, unexpected '?', expecting variable (T_VARIABLE)
in PDOConnection.php line 24

CLI version is 7.2 on the server, and phpinfo() shows 5.6.40. The error shows on pages where DB access is needed. When there's no DB requests it works fine.

Thanks :)

  • Check this on server PHP >= 5.6.4 OpenSSL PHP Extension PDO PHP Extension Mbstring PHP Extension Tokenizer PHP Extension XML PHP Extension – Mayank Dudakiya Apr 09 '19 at 12:39
  • Possible duplicate of [PHP parse/syntax errors; and how to solve them?](https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – aynber Apr 09 '19 at 12:40
  • 1
    Sounds like you need to fix the web server to use 7.2 instead of 5.6. – aynber Apr 09 '19 at 12:41

3 Answers3

3

PDOConnection.php is a file from doctrine/dbal package, and its line 24 is incompatible with PHP 5.4 (using ?array).

Laravel 5.4 has doctrine/dbal~2.5 in its require-dev, but in version 2.5 there is no such issue (line 40).

It seems that you have to delete vendor folder and run composer install again, that will install needed dependencies.


Added:

@aynber pointed that your issue is with installing dependencies with PHP 7.2 and running on PHP 5.6, so after removing vendor folder and before reinstalling you should add this to your composer.json:

"config": {
    "platform": {
        "php": "5.6.40"
    }
}

Source

Styx
  • 9,863
  • 8
  • 43
  • 53
  • 1
    First they need to fix it so that CLI and Web versions of PHP match, or else the OP will still run into versioning issues. – aynber Apr 09 '19 at 12:50
  • @aynber Actually, that's not important. PHP 5.4 code will still run on 7.2, isn't it? – Styx Apr 09 '19 at 12:54
  • Yes, but Composer will install code meant for 7.2, which won't work for the web version running on 5.6. If CLI was 5.6 and the Web was 7.2, it wouldn't be as much of an issue. – aynber Apr 09 '19 at 12:56
  • @aynber I thought Composer would install code according to `composer.json` and of versions specified there, no? :) – Styx Apr 09 '19 at 12:57
  • Yes, to a certain extent. It will install the framework dependencies, but some of them have some leeway as far as packages go. That is, it will install the most recent available for the current requirements. There's apparently a bug issue similar, found at `https://github.com/laravel/framework/issues/20591`, where one of the suggested fixes is to specify the php version in the composer.json. – aynber Apr 09 '19 at 13:01
  • @aynber Yes, you're correct, thank you. I'll update my answer now. – Styx Apr 09 '19 at 13:04
  • @Styx thanks, I changed the CLI version to 5.6.40 too, and added the "config": { "platform": { "php": "5.6.40" } } in composer.json file. I removed the vendor folder, and when i did composer install, i am getting dependency errors now: Problem 1 - Installation request for doctrine/cache v1.8.0 -> satisfiable by doctrine/cache[v1.8.0]. - doctrine/cache v1.8.0 requires php ~7.1 -> your PHP version (5.6.40) does not satisfy that requirement – user3384126 Apr 09 '19 at 13:59
  • I can't change the php version, because there's some old code on the server that uses mysql queries and won't work on PHP7. – user3384126 Apr 09 '19 at 14:00
  • @user3384126 Try to omit dev packages: `composer install --no-dev` – Styx Apr 09 '19 at 14:33
0

Are you sure you're using Laravel 5.4? Laravel 5.4 should be using doctrine/dbal@~2.5 where there is only a comment on line 24. It appears you are using at least version 2.9, which uses nullable types which is only available in PHP 7.1+.

Your options:

  1. Update your PHP version
  2. Remove and reinstall laravel/framework@5.4
Thomas
  • 8,426
  • 1
  • 25
  • 49
  • I changed the CLI version to 5.6.40 too, and added the "config": { "platform": { "php": "5.6.40" } } in composer.json file. I removed the vendor folder, and when i did composer install, i am getting dependency errors now: Problem 1 - Installation request for doctrine/cache v1.8.0 -> satisfiable by doctrine/cache[v1.8.0]. - doctrine/cache v1.8.0 requires php ~7.1 -> your PHP version (5.6.40) does not satisfy that requirement. – user3384126 Apr 09 '19 at 13:57
0

Thanks for your help, i fixed the problem.

I cleared the composer cache with 'composer clearcache', then i ran:

composer which, which returned the composer path

and then i ran

php -d allow_url_fopen=on COMPOSER_PATH_FROM_PREV_STEP update

and it updated all dependencies to work with PHP5.6 :)