Laravel parse error: syntax error, unexpected T_CLASS, expecting T_STRING or T_VARIABLE

How can I fix the HTTP ERROR 500:

Laravel parse error: syntax error, unexpected T_CLASS, expecting T_STRING or T_VARIABLE


Origin:

Laravel 5.1 and higher 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 or higher. Your installed PHP version is probably older than 5.5. Try to update your PHP binary.

Why is ::class appended to PHP class in Laravel 5.1 and higher

The feature has been introduced with version 5.5, which is now required by Laravel 5.1 or higher

The magic ::class property holds the FQN (fully qualified name) of the class.

The advantages of it mostly comes with a good IDE. Some are:

Sometimes it’s also nice that you can import the class instead of having the full name in the code. This makes your code cleaner and all dependencies are declared with use at the top of the class. (I’m saying sometimes because for one it doesn’t make sense to import all classes in a config file like app.php)


Solution:

Laravel 5.5 and higher requires PHP 7.0.0 or greater.

And please make sure you have these components on your server before install the script:

PHP 7.0.0 or greater
OpenSSL PHP Extension
PDO PHP Extension
Mbstring PHP Extension
Tokenizer PHP Extension
XML PHP Extension
GD or Imagick
PHP Fileinfo extension
PHP Zip Archive

To check the PHP version installed on your server, create a php file (ex: /phpinfo.php) on your server with the content below:

<?php
phpinfo();