简体   繁体   English

Laravel 解析错误:语法错误,意外的 T_CLASS,在 artisan 中期待 T_STRING

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

I checked my php version:我检查了我的 php 版本:

PHP 7.0.27 (cli) (built: Jan 23 2018 09:07:32) ( NTS ) PHP 7.0.27 (cli)(构建时间:2018 年 1 月 23 日 09:07:32)(NTS)
Copyright (c) 1997-2017 The PHP Group版权所有 (c) 1997-2017 PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies Zend Engine v3.0.0,版权所有 (c) 1998-2017 Zend Technologies

图片 php 版本在这里

But this is the error that appears when doing cron job但这是做cron作业时出现的错误

Parse error : syntax error, unexpected T_CLASS, expecting T_STRING or T_VARIABLE or '$' in /path_to_project/artisan on line 31解析错误:语法错误,意外的 T_CLASS,在第31行的/path_to_project/artisan 中需要T_STRING 或 T_VARIABLE 或“$”
X-Powered-By: PHP/5.3.29 Content-type: text/html X-Powered-By:PHP/5.3.29 内容类型:text/html

and I used this to test this code我用它来测试这段代码

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

?>

The output is :Foo输出是: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.无论运行什么,它都使用旧的 PHP 版本。

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请参阅有关如何修复它的类似问题: Laravel 解析错误:语法错误,意外的 T_CLASS,期望 T_STRING 或 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.此答案还建议使用php-cli来运行您的代码而不是phphttps : //stackoverflow.com/a/41776870/7417402这可能解释了为什么您会得到不同的版本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Laravel解析错误:语法错误,意外T_CLASS,期待T_STRING - Laravel parse error: syntax error, unexpected T_CLASS, expecting T_STRING Cakephp 解析错误:语法错误,意外的“类”(T_CLASS),需要标识符(T_STRING) - Cakephp Parse error: syntax error, unexpected 'Class' (T_CLASS), expecting identifier (T_STRING) 解析错误:语法错误,意外的“ href”(T_STRING),期望为“,”或“;” - Parse error: syntax error, unexpected 'href' (T_STRING), expecting ',' or ';' PHP Parse错误:语法错误,意外T_CLASS - PHP Parse error: syntax error, unexpected T_CLASS 解析错误:语法错误,意外的&#39;]&#39;,预期为T_STRING或T_VARIABLE或T_NUM_STRING - Parse error: syntax error, unexpected ']', expecting T_STRING or T_VARIABLE or T_NUM_STRING 错误:(!)分析错误:语法错误,意外的&#39;&#39;(T_ENCAPSED_AND_WHITESPACE),需要标识符(T_STRING) - Error : ( ! ) Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) 解析错误:语法错误,意外的“;”,需要标识符(T_STRING)或变量(T_VARIABLE) - Parse error: syntax error, unexpected ';', expecting identifier (T_STRING) or variable (T_VARIABLE) Wordpress-解析错误:语法错误,意外的“函数”(T_FUNCTION),期望的标识符(T_STRING) - Wordpress - Parse error: syntax error, unexpected 'function' (T_FUNCTION), expecting identifier (T_STRING) PHP后期静态绑定—分析错误:语法错误,意外的T_STRING,预期的T_VARIABLE - PHP Late Static Binding — Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE 解析错误:语法错误,意外的&#39;(&#39;,期望T_STRING或T_VARIABLE或&#39;与PDO - Parse error: syntax error, unexpected '(', expecting T_STRING or T_VARIABLE or ' with PDO
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM