Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Parse error: syntax error, unexpected '?' in helpers.php 233

Tags:

laravel-5.5

When I create a new Laravel project, the browser displays an error 500. I found this in the log:

PHP Parse error: syntax error, unexpected '?' in vendor/laravel/framework/src/Illuminate/Foundation/helpers.php on line 233

the code in 233 is:

return app('cache')->get($arguments[0], $arguments[1] ?? null);

But as i know, null coalescing operator( ?? ) is supported from PHP 7.0

My PHP Version:

PHP 7.1.8-2+ubuntu14.04.1+deb.sury.org+4 (cli) (built: Aug 4 2017 14:34:05) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.1.8-2+ubuntu14.04.1+deb.sury.org+4, Copyright (c) 1999-2017, by Zend Technologies

Laravel Version: 5.5.0

Who knows what happened?

like image 259
Cui Mingda Avatar asked Sep 01 '17 02:09

Cui Mingda


3 Answers

If I had to guess, I'd say you installed the PPA 7.1.8 as CLI only (php7-cli). You're getting your version info from that, but your libapache2-mod-php package is still 14.04 main which is 5.6. Check your phpinfo in your browser to confirm the version. You might also consider migrating to Ubuntu 16.04 to get PHP 7.0 in main.

like image 154
roktechie Avatar answered Oct 31 '22 19:10

roktechie


I had approximately the same problem with Laravel 5.5 on ubuntu, finally i've found a solution here to switch between the versions of php used by apache :

  1. sudo a2dismod php5
  2. sudo a2enmod php7.1
  3. sudo service apache2 restart

and it works

like image 17
Mouhamed Fadel Diagana Avatar answered Oct 31 '22 19:10

Mouhamed Fadel Diagana


If you came across this error while using the command line its because you must be using php 7 to execute whatever it is you are trying to execute. What happened is that the code is trying to use an operator thats only available in php7+ and is causing a syntax error.

If you already have php 7+ on your computer try pointing the command line to the higher version of php you want to use.

export PATH=/usr/local/[php-7-folder]/bin/:$PATH

Here is the exact location that worked based off of my setup for reference:

export PATH=/usr/local/php5-7.1.4-20170506-100436/bin/:$PATH

The operator thats actually caused the break is the "null coalesce operator" you can read more about it here:

php7 New Operators

like image 1
James Fannon Avatar answered Oct 31 '22 20:10

James Fannon