-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?

Devstr
  • 4,431
  • 1
  • 18
  • 30
JRa
  • 1
  • 2
  • 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. – Devstr Feb 13 '18 at 00:29
  • updated error not cuz code that artisan file belong to laravel – JRa Feb 13 '18 at 00:36
  • quick search discovers many similar questions, all point to old PHP version: https://stackoverflow.com/questions/32205590/laravel-parse-error-syntax-error-unexpected-t-class-expecting-t-string-or-t-v – Devstr Feb 13 '18 at 00:40
  • Possible duplicate of [Laravel parse error: syntax error, unexpected T\_CLASS, expecting T\_STRING or T\_VARIABLE](https://stackoverflow.com/questions/32205590/laravel-parse-error-syntax-error-unexpected-t-class-expecting-t-string-or-t-v) – Devstr Feb 13 '18 at 00:41
  • i know but my php version 7.0.27 – JRa Feb 13 '18 at 00:41
  • can you verify that by adding `phpinfo();` in the artisan file? – Devstr Feb 13 '18 at 00:42
  • and i post the version in question i searched in questions that u menthioned – JRa Feb 13 '18 at 00:42
  • phpinfo() PHP Version => 7.0.27 – JRa Feb 13 '18 at 00:43
  • 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. – ceejayoz Feb 13 '18 at 02:25

1 Answers1

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.

Devstr
  • 4,431
  • 1
  • 18
  • 30