Home > Software design >  Migration 6 to 7 Laravel Error Parse error: syntax error, unexpected '=' in \vendor\symf
Migration 6 to 7 Laravel Error Parse error: syntax error, unexpected '=' in \vendor\symf

Time:07-13

I'm having this error when migrating a project from laravel 6 to 7 does anyone have an idea how I can solve it. I've already tried to delete the vendor file and redo the installation from 0 with composer install but I still get the same error. I really don't know what's going on. Thanks in advance. Any help is welcome.

Parse error: syntax error, unexpected '=' in C:\projetos\curso\vendor\symfony\string\Resources\functions.php on line 34
PHP Parse error:  syntax error, unexpected '=' in C:\projetos\curso\vendor\symfony\string\Resources\functions.php on line 34

My Composer .json

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.2",
        "fideloper/proxy": "^4.0",
        "guzzlehttp/guzzle": "^6.3",
        "laravel/framework": "^7.0",
        "laravel/horizon": "^4.0",
        "laravel/tinker": "^2.0",
        "psr/log": "^1.1.4",
        "stripe/stripe-php": "^8.10"
    },
    "require-dev": {
        "filp/whoops": "^2.0",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^4.1",
        "phpunit/phpunit": "^8.5"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "files": [
            "app/helpers.php"
        ],
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
    "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"
        ]
    }
}

functions.php --->

<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\String;

if (!\function_exists(u::class)) {
    function u(?string $string = ''): UnicodeString
    {
        return new UnicodeString($string ?? '');
    }
}

if (!\function_exists(b::class)) {
    function b(?string $string = ''): ByteString
    {
        return new ByteString($string ?? '');
    }
}

if (!\function_exists(s::class)) {
    /**
     * @return UnicodeString|ByteString
     */
    function s(?string $string = ''): AbstractString
    {
        $string ??= '';  <---Line 34

        return preg_match('//u', $string) ? new UnicodeString($string) : new ByteString($string);
    }
}

CodePudding user response:

The line 34 error in vendor\symfony\string\Resources\functions.php

$string ??= '';

This is a Null Coalescing Assignment Operator - https://wiki.php.net/rfc/null_coalesce_equal_operator#:~:text=coalescing operator being a comparison,not null, nothing is made.

As stated in the link above this has been implemented in PHP 7.4. You will need to update your PHP version to 7.4

  • Related