Search code examples
phplaravelxamppcomposer-phplaravel-artisan

Can't run artisan commands on cmd because of parse error


The error is:

Parse error: syntax error, unexpected 'class' , expecting identifier or variable OR '{' OR '$' in c:\xampp\htdocs\laravel\artisan on line 31.

First of all, I haven't made this project but it was running with no problems(it still seems to run ok but I can't run any artisan commands!!). The version of laravel it was running was 5.2 while php was 5.4.31 as it is shown on cmd, although when I run phpinfo() function on xampp it shows 5.6.23. Why is that?

I haven't changed one bit of the code. It started doing this after I had been trying to create another project of laravel in a local folder. Every time I deleted it and installed it again, it kept downloading it on laravel 5.0. What can I do?

I can't update php version because there are a lot of projects that are running on the server and I am afraid I will mess it up.


Solution

  • 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.2 on PHP 5.4.

    So to solve this, in your windows environment, simply point php to run on your php 5.6 variant and that should solve it.