syntax error, unexpected ')' after Laravel update

Viewed 5165

I have updated my laravel project to "laravel/framework": "^8.12" from laravel 5.7, but after updating when I run composer dump-autoload it returns this error

Generating optimized autoload files> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

In TestDatabases.php line 148:

  syntax error, unexpected ')'

here is my composer.json

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.3|^8.0",
        "fideloper/proxy": "^4.4",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "intervention/image": "^2.5",
        "laravel/framework": "^8.12",
        "laravel/sanctum": "^2.8",
        "laravel/tinker": "^2.5",
        "laravel/ui": "^2.0",
        "barryvdh/laravel-dompdf": "^0.8.3",
        "nao-pon/flysystem-google-drive": "~1.1",
        "spatie/laravel-backup": "^6.14"
    },
    "require-dev": {
        "facade/ignition": "^2.5",
        "fakerphp/faker": "^1.9.1",
        "laravel/sail": "^1.0.1",
        "mockery/mockery": "^1.4.2",
        "nunomaduro/collision": "^5.0",
        "phpunit/phpunit": "^9.3.3"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        },
        "files": [
            "app/Helpers/helpers.php",
            "app/Helpers/agent_helper.php",
            "app/Helpers/user-helpers.php"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}


how to solve this error?

4 Answers

You need to upgrade your PHP installation to at least version 7.3 to resolve the issue.

PHP 7.2 is EOL (end of life) since 30 Nov 2020!

As already stated in the comments:

Laravel 8 requires php 7.3 or higher

Larvel 8 has the following PHP version constraint in composer.json:

"require": {
  "php": "^7.3|^8.0"
}

Do NOT run composer with the --ignore-platform-reqs flag unless you have a (very rare) valid reason to do so.

I had the same issue after updating Ubuntu to version 20. I had both php 7.4 and php 7.2 versions on my machine. I set my dev environ to php 7.2 to run an older Laravel 5.6 web app, but is also working on a Laravel 8 web app.
I got the same error In TestDatabases.php line 159: syntax error, unexpected ')' when I tried php artisan serve for Laravel 8.

I solved the error by running the following commands in terminal (directory is inconsequential):

user1@user1-Ubuntu:/var/www/html/laravel8-website$sudo a2dismod php7.2
user1@user1-Ubuntu:/var/www/html/laravel8-website$sudo a2enmod php7.4
user1@user1-Ubuntu:/var/www/html/laravel8-website$sudo update-alternatives --set php /usr/bin/php7.4
user1@user1-Ubuntu:/var/www/html/laravel8-website$sudo systemctl restart apache2

At first I had not run the command update-alternatives --set php /usr/bin/php7.4 and only disabled php7.2 and enabled 7.4 then restarted the server. But still got the above error despite phpinfo() method telling me I have php7.4.20 running.
I checked php version using php -v command in terminal and got PHP 7.2.34-22+ubuntu20.04.1+deb.sury.org+1 (cli) (built: Jun 4 2021 21:22:16) ( NTS ) output.

The golden nugget in this wordy answer was also running sudo update-alternatives --set php /usr/bin/php7.4 command in terminal and restarting server. It works vice versa also.

I have the same thing with latest php and latest laravel. I got my files from github laravel\laravel. I fixed it but not sure if it's my mistake (proably is) or if it's actually a bug in the code?

in /vendor/laravel/framework/src/Illuminate/Testing/Concerns/TestDatabases.php On line 158 and 163, at the end of the line there is a comma, which is followed by a close bracket ). So I took out the comma at the end of both lines and now there is no problem at all.

I also faced the Same Issue. After upgrading to 7.3, it solved. Upgrade PHP 7.2 to 7.3/higher, it will be solved.

Steps for upgrading to 7.3:
Check your current PHP version.

# php -v
PHP 7.2.36

In order to install PHP 7.3, we need to add the repository first:

# add-apt-repository ppa:ondrej/php

Then run an update:

# apt-get update

After completing the update, we need to install the PHP 7.3.

# apt install php7.3 

Then install the required PHP packages based on your current installation:

# apt install php7.3-common php7.3-cli php7.3-bz2 php7.3-curl php7.3-gd php7.3-intl php7.3-json php7.3-readline php7.3-xml php7.3-zip php7.3-fpm php7.3-bcmath php7.3-mbstring

After a successful installation, we can disable the old 7.2 and then enable 7.3:

# a2dismod php7.2

# a2enmod php7.3

Then restart Apache:

# service apache2 restart

The new PHP version should be active now. You can verify it from the command line:

# php -v
PHP 7.3.28
Related