Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

peffraimidis's avatar

php artisan syntax error

Hello, I uploaded one of my projects to a server and I'm using task scheduling in it. I added the cronjob as the documentation says but it seems that something is wrong with the artisan command.

PHP Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in .../artisan on line 31

I am using Laravel Framework 5.7.28 and PHP 7.3.8

Locally on my machine, everything works as expected!

0 likes
7 replies
uksarkar's avatar

Hi @pefremidis If you open up the artisan file, you will see line 31 is doing this:

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

::class is only available from PHP 5.5 onwards so, tl;dr, you can't run Laravel 5.7.* on PHP 5.4.

This is happening because your server is running an older version of PHP. If you check your PHP version by CLI php -v then make sure that create a info.php file and write phpinfo() then check the version.

peffraimidis's avatar

Thanks for the feedback @utpal2015, @mvd. Unfortunately, this is not the case. I created an info.php file and as I mentioned me the version of PHP is 7.3.8 :(

Snapey's avatar

check directly from the command line with php -v

peffraimidis's avatar

@utpal2015, @snapey you were right. The server's PHP version is old. They have installed PHP 5.4.16

So just to make it clear, in my case phpinfo() gave a different version that the php -v

cometads's avatar
cometads
Best Answer
Level 3

This can happen on servers managed with software like cPanel. Multiple versions of PHP are installed to allow different PHP versions on a per site basis. So even though phpinfo() (FPM) is on 7.x, the command line (CLI) is not necessarily the same version.

As a work around you can find out where the proper PHP 7.x CLI binary is and directly call that instead of the bash alias.

siangboon's avatar

web and cli may calling different global environment set hence we have to always be aware....

Please or to participate in this conversation.