37

After installing laravel we get an error:

Parse error: syntax error, unexpected T_CLASS, expecting T_STRING or T_VARIABLE or '$' in C:\xampp\htdocs\laravel\public\index.php on line 50

2
  • I still have this problem, and we cannot put our laravel application live. We are using php 5.6. for apache and for command line. "php -v" gives "5.6" Commented Aug 10, 2017 at 15:46
  • Did you create key?
    – Agil
    Commented Feb 25, 2018 at 10:57

5 Answers 5

46

Laravel 5.1 uses the ::class property to get string representations of a fully qualified classname. The error you're seeing is caused by this line

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

This language feature has been introduced in PHP 5.5 which is a requirement of Laravel 5.1. Your installed PHP version is probably older than 5.5. Try to update your PHP binary.


In case you are interested in why ::class is used, take a look at this answer

4
  • I am using php 5.6.0, but still i am getting Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in C:\wamp\www\laravelmaster\public\index.php on line 50 , i checked from cmd like php -v and using laravel 5.2 Commented May 30, 2016 at 9:52
  • 3
    @151291 Your CLI version of php (the one you get with php -v) might be different from the one the webserver uses. Put phpinfo() in a PHP file and open it in your browser. There you should see the actual version your server uses... Commented May 30, 2016 at 13:05
  • 1
    Hi, My CLI version as well as version of PHP showing in phpinfo is 7.1.22 but still I am getting same error. Can you please help? why I am getting this error still? Thanks
    – Dhirender
    Commented Sep 30, 2018 at 9:59
  • @Dhirender - I know this is old, but for others, this error also happens for me when I forget a ; after a use statement for a class I'm adding referencing in a class.
    – timbrown
    Commented Jul 25, 2019 at 21:48
7

Same thing happened to me also. I found that web server was using my old PHP version 5. To solve it for me, I did this -

sudo a2dismod php5
sudo a2enmod php7.0
sudo service apache2 restart
2
  • 1
    This was my issue, and php -v on the command line was using 7.1 but the server was still on php5
    – willcwf
    Commented May 23, 2018 at 17:38
  • Hi, My CLI version as well as version of PHP showing in phpinfo is 7.1.22 but still I am getting same error. Can you please help? why I am getting this error still? Thanks
    – Dhirender
    Commented Sep 30, 2018 at 9:59
4

Your php version is too low. Try version 7.0 or later php.

2

Your PHP version on your Xampp is lower than 5.5.9 as specified in the Laravel 5.1 doc.

Simply uninstall your current Xampp software and download a fresh copy at Apache website with this specification 5.6.12 / PHP 5.6.12 .

Do not forget to collaborate with your host provider to ensure that your hosting account runs the required PHP version (>=5.5.9) during the deployment of your Laravel 5.1 app online.

1
  • Yeah version might cause that too. But make sure you get version actuallyorking on your server, virtual machine or whatever you are using
    – Agil
    Commented Feb 25, 2018 at 10:59
0

I was facing the same error but error was in app/User.php line 10. Actually, line 10 was ok but before line 10 I was missing some php syntax.

After correct the php syntax error It was fixed. So you have to check C:\xampp\htdocs\laravel\public\index.php on line 49 carefully I am sure there is something wrong. Just try to correct. It will be fixed.

Not the answer you're looking for? Browse other questions tagged or ask your own question.