-1

I checked my php version:

PHP 7.0.27 (cli) (built: Jan 23 2018 09:07:32) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

Image php Version here

But this is the error that appears when doing cron job

Parse error: syntax error, unexpected T_CLASS, expecting T_STRING or T_VARIABLE or '$' in /path_to_project/artisan on line 31
X-Powered-By: PHP/5.3.29 Content-type: text/html

and I used this to test this code

<?php 
class Foo{}
echo Foo::class;

?>

The output is :Foo

artisan file

#!/usr/bin/env php
<?php
require __DIR__.'/bootstrap/autoload.php';

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


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

$status = $kernel->handle(
$input = new Symfony\Component\Console\Input\ArgvInput,
new Symfony\Component\Console\Output\ConsoleOutput
);

$kernel->terminate($input, $status);

exit($status);

I run it like this:

* * * * * php /path_to_project/artisan schedule:run >> /path_to_project/log.txt
* * * * * php-cli -q /path_to_project/artisan  schedule:run >> /path_to_project/log.txt

How do I resolve this error?

9
  • so what is on the line 31? could you post the relevant snippet? It's hard to see where error is if you don't show relevant code. Commented Feb 13, 2018 at 0:29
  • updated error not cuz code that artisan file belong to laravel Commented Feb 13, 2018 at 0:36
  • quick search discovers many similar questions, all point to old PHP version: stackoverflow.com/questions/32205590/… Commented Feb 13, 2018 at 0:40
  • Possible duplicate of Laravel parse error: syntax error, unexpected T_CLASS, expecting T_STRING or T_VARIABLE Commented Feb 13, 2018 at 0:41
  • 1
    Ask your host. I'd guess your CLI is configured to use a particular PHP, perhaps via .profile or .bash_profile, and that cron doesn't use that profile. Commented Feb 13, 2018 at 2:25

1 Answer 1

1

How do you run your code? Whatever is running it uses old PHP version.

It says it right here:

X-Powered-By: PHP/5.3.29

see similar question on how to fix it: Laravel parse error: syntax error, unexpected T_CLASS, expecting T_STRING or T_VARIABLE

Also this answer suggests using php-cli to run your code instead of php: https://stackoverflow.com/a/41776870/7417402 This might explain why you get different versions.

Sign up to request clarification or add additional context in comments.

1 Comment

how do you run your code? what is the command you are using? are you running it via cron?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.