简体   繁体   中英

Laravel parse error: syntax error, unexpected T_CLASS, expecting T_STRING in artisan

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

图片 php 版本在这里

But this is the error that appears when doing cron job

: syntax error, unexpected T_CLASS, expecting T_STRING or T_VARIABLE or '$' in on line :语法错误,意外的 T_CLASS,在第行的T_STRING 或 T_VARIABLE 或“$”
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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM