Framework: PHP Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in laravel/framework/src/Illuminate/Foundation/helpers.php on line 476

Created on 6 Dec 2016  Â·  33Comments  Â·  Source: laravel/framework

  • Laravel Version: 5.3.26
  • PHP Version: PHP 5.6.28-1+deb.sury.org~trusty+1 (cli)

Description:

I have a fresh install of Laravel everything is working on my local where I'm using PHP 5.6.22 but on my production server where I have php 5.6.28 I have this error :

[Tue Dec 06 10:40:56.435993 2016] [:error] [pid 3951] [client 213.55.176.229:38035] PHP Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in vendor/laravel/framework/src/Illuminate/Foundation/helpers.php on line 476

Steps To Reproduce:

install the last version of laravel with php 5.6.28

Most helpful comment

Thanks. Solved it for me as well. Here's a quick snippet for any others who may find this.

sudo a2dismod php5 && sudo a2enmod php5.6 && sudo service apache2 restart

All 33 comments

Content of line 476:

function event(...$args)
{
    return app('events')->fire(...$args);
 }

Seems that your PHP version doesn't support the splat operator, which means that it isn't PHP5.6...

Please check the version of php running on your webserver, matches that in the console.

Ah thanks you! You are right my php cli was 5.6 but the apache version was 5.5.9

Everything is fine now

Have a nice day

Thanks. Solved it for me as well. Here's a quick snippet for any others who may find this.

sudo a2dismod php5 && sudo a2enmod php5.6 && sudo service apache2 restart

Great.
that worked for me also.

Hello. I am getting this error with php 7.1. On php 5.6.30 its works fine. :)

I have the same problem .. laravel 5.4 with php 7.0 or 5.6.29 doesnt works.
Any solution?
Tks

Thanks guys, I was stuck on this for so long, sannysc's snippet worked for me on laravel 5.4 on digital ocean ubuntu 14.04 LAMP

I am having the same problem with PHP 7.0.16 too (Laravel 5.3).

Guys, just check that you're running different PHP versions from different *nix users.

Guys check that if you are in local envirmoment and using something like MAMP that the bash profile loads the MAMP php version and not default from mac. Take a look to https://gist.github.com/irazasyed/5987693
Everytime you update mamp and your hosts php version you will need to do this.

Like vimalmistry and Sennik, I'm having the same problem with PHP 7.1.2 but working with 2 docker containers. One with nginx:1.10 and other with php:7-fpm. using laravel 5.4
When I was enabled the display_errors, I received the below message:
Parse error: syntax error, unexpected '$kernel' (T_VARIABLE) in /var/www/public/index.php on line 50

Same issue here.

Have the following cron job: cd /home/user/www && php ./artisan schedule:run

This executes /usr/local/php56/bin/php artisan queue-process-listener

I'm getting the following error:

Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in /home/user/www/vendor/laravel/framework/src/Illuminate/Foundatio n/helpers.php on line 477

PHP returns:

% php -v
PHP 5.6.29 (cli) (built: Dec 9 2016 23:39:41)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

% /usr/local/php56/bin/php -v
PHP 5.6.29 (cli) (built: Dec 9 2016 23:39:41)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

Same here php7.0, laravel 5.4

Even when specifying the PHP to use (7.1.1), it produced the error.

This fixed it for me, by changing the profile to point to the MAMP 7.1.1 install, and not having to run: php composer.phar, just composer.phar

https://gist.github.com/irazasyed/5987693

Thanks @sannysc . It Works :D

I have also this error with php 7.1 (shows from console) and Laravel 5.4.
Check php path from your local:
$ which php
/usr/local/bin/php
Give this full path in your Crontab
* * * * * /usr/local/bin/php /Users/abhilash/my-site/artisan schedule:run >> /dev/null 2>&1

It works Fine :)

It was my first day with vagrant and laravel.
I was adding a controller with php artisan make:controller PagesController function and that was generating this error.

The issue was I was doing this from host. And host had the older version of php. I ssh'ed into the server and then ran this command again, and everything worked fine.

I hope, it will help others.

If you are using Plesk ant want to use a different PHP version you can do this: export PATH=/opt/plesk/php/7.0/bin:$PATH; php artisan key:generate (7.0 or version number of course depending on what is available on the server)

hen someone can help me out with this?
Parse error: syntax error, unexpected '-', expecting ']' in /storage/ssd4/198/4185198/public_html/pr.php on line 25

im totaly new in php so pleas don't judge me...thx

i curently have PHP version: 7.0.26

Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips

After you install php7 use this so type this into your command line so that the version changes on the shell ( export PATH=/usr/local/php71/bin:$PATH )

Hey after my research i found this working for me , replace what you have under public/.htaccess with the following



Options -MultiViews

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

i am running ubuntu 16.04, laravel 5.6, for me, it was

sudo a2dismod php5 && sudo a2dismod php5.6 && sudo a2enmod php7.1 && sudo service apache2 restart

Where did you type that? @udoy-touhid

who are you?

On Fri, Aug 10, 2018 at 6:23 PM, Luiz Wynne notifications@github.com
wrote:

Where did you type that? @udoy-touhid https://github.com/udoy-touhid

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/laravel/framework/issues/16674#issuecomment-412116260,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AhiXER8xofmdogxCzYcSbgeG51f0WZw-ks5uPaWHgaJpZM4LFQ_A
.

Laravel 5.4 require php 7.1 version for me. Lower version not working. :D

Make sure the php version matches that on your local server. Had a similar ecounter and this should fix the issue

my php version 7.2.24 and 5.3 laravel version. any solution.?

I am facing a problem when trying to run from localhost:
I have installed PHP 7.4.7
My XAMPP folder installed in D Drive.
http://127.0.0.1:8000/ is working.
But,
http://localhost/Laravel/Laravel/public/ (Shows bellow error)

Parse error: syntax error, unexpected T_CLASS, expecting T_STRING or T_VARIABLE or '$' in D:\xampp\htdocs\Laravel\Laravel\public\index.php on line 52

At Line 52:
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

Index.php as:

/**

  • Laravel - A PHP Framework For Web Artisans
    *
  • @package Laravel
  • @author Taylor Otwell taylor@laravel.com
    */

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/

require __DIR__.'/../vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__.'/../bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

i'm also error same you

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fideloper picture fideloper  Â·  3Comments

Anahkiasen picture Anahkiasen  Â·  3Comments

lzp819739483 picture lzp819739483  Â·  3Comments

shopblocks picture shopblocks  Â·  3Comments

progmars picture progmars  Â·  3Comments