framework: Syntax Error with Laravel 5.5 and PHP 7.0.27 within Mail function

  • Laravel Version: 5.5.32
  • PHP Version: 7.0.27

Description:

Parse error: syntax error, unexpected '?', expecting variable in /vendor/symfony/css-selector/XPath/Extension/AttributeMatchingExtension.php

Steps To Reproduce:

It happens when I am trying to send an email using Mail::to()…

It doesn’t happen with PHP 7.1.8. How to fix this issue without downgrading Laravel version (with 5.4 worked, as I recall) or changing PHP (because this version is on shared server and I am unable to change it)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

You need to use the platform config to lock to the version of php you want to use:

{
    ...
    "config": {
        "platform": {
            "php": "7.0.27"
        },
    ...
    },
    ...
}

Yes, it is 7.0.27. The error is occurred on lines: 46, 51, 56 ?string $value this new nullable type syntax is introduced since php 7.1, but Laravel 5.5 requires at least 7.0, not 7.1, hence the issue…

Some Symfony packages are incompatible (introduction of nullable concept in PHP) with PHP 7.0. This means that Laravel 5.5 requires effectively PHP 7.1.

As far as I can see nullable types were only added to PHP in v7.1, but the required version is >=7.0.0 The issue appears to be with Symfony, but if Laravel 5.5 is a LTS version perhaps the PHP requirement should be updated to 7.1?

Composer packages are only installed and updated locally on 7.1 and copied to server, where is 7.0.

Yeah - you cant do this. The problem is composer is installing packages that need PHP 7.1 - because you are running PHP7.1.

If you want to run on PHP7.0- then you must run composer update (not install) on the PHP7.0 machine, and it will handle it correctly for you.

Did it give a line number?

Are you sure your running PHP7? That error looks alot like PHP5.6 trying to run PHP7 code…