We help IT Professionals succeed at work.

Unexpected ? in Laravel

Bruce Gust
Bruce Gust asked
on
So, I'm on vacation and wanted to work a little bit on a project I'm trying to wrap up.

I bring my project on a separate drive, install it in my WAMP directory and go to run "php aristan migrate" and this is what I get:

brucegust@BRUCEGUST7EFC MINGW64 /c/wamp64/www/new_nomas (bruce)
$ php artisan migrate

Parse error: syntax error, unexpected '?' in C:\wamp64\www\new_nomas\vendor\lara
vel\framework\src\Illuminate\Foundation\helpers.php on line 500

brucegust@BRUCEGUST7EFC MINGW64 /c/wamp64/www/new_nomas (bruce)
$ php -v
PHP 5.6.40 (cli) (built: Jan  9 2019 15:10:36)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

brucegust@BRUCEGUST7EFC MINGW64 /c/wamp64/www/new_nomas (bruce)
$ php artisan laravel

Parse error: syntax error, unexpected '?' in C:\wamp64\www\new_nomas\vendor\laravel\framework
\src\Illuminate\Foundation\helpers.php on line 500

Open in new window


I'm running PHP 7 on my box. The Laravel project I'm working on is also coming from a PHP 7 dynamic, so I don't know where the PHP 5.6.4 is coming from, but from what I've been able to determine, the error that I'm getting is because of PHP mismatch.

How do I fix it?
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019

Commented:
Hey Bruce,

When you run a WAMP stack, you have 2 versions of PHP - the version your website runs and the version the command line runs (CLI). When you run php -v, it will give you the version of PHP that is referenced in your PATH environment. It is possible that you have more than one version of PHP on your system, and the PATH is pointing to an older version.

Have a look in your WAMP directory, under a folder called bin. You'll probably see several versions of PHP in there, including your 5.6.4 plus your v 7.x.x. From a command prompt, type 'path' and press enter. You'll probably see that you have the old 5.6.4 path referenced in there.

You have a few choices. You can either change the path to point to the correct version (head to your Control Panel | System | Advanced System Settings | Environment Variables) , or you can fully qualify the php exe when you run your artisan commands:

c:\wamp\bin\php\php7.3.3\php.exe artisan migrate

Open in new window

If you're using WAMP server, you may also be able to change the CLI version directly (depending on your version of WAMPServer). Right-click on the WAMP icon in your task bar, select Tools, and you'll see a menu item that says "Change PHP CLI Version" - just select the v7 version).

FYI - the error you're getting is because in the helpers.php file, they're using the null coalescing operation ( a double ?? ) which only works in v7
Bruce GustPHP Developer

Author

Commented:
Hey, Chris!

I changed my PATH so I'm running PHP 7

screenshot
This is my laptop. I'm on vacation and I was just hoping to get a little more work done. By the time I get this figured out, I'll be back home. But it's still healthy to understand what's going on.

What else could be causing this error?
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019
Commented:
Hey Bruce,

That screenshot you're showing is for the Web version of PHP (what get's ran when you load up a page in your browser). The version of PHP used by Apache can be different to the one being used by the command line.

From the Command Line, when you type 'php; it will run whatever version of php.exe it find's in your PATH. If it's still finding the older version, then you probably haven't updated your path correctly. Type 'path' at the command prompt and see what you get - it should include the path to the version of PHP you want to run from the CLI.
Bruce GustPHP Developer

Author

Commented:
Thanks, Chris!

I'm going to keep your comments on record in case I run into this again!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.