php 意外的“类”(T_CLASS)仅在远程(不在本地)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29862558/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
unexpected 'class' (T_CLASS) only on remote (not in local)
提问by user3553866
We are developping a CRM.
我们正在开发 CRM。
In local, I have no problem, but in remote (OVH), I have this error message :
在本地,我没有问题,但在远程(OVH)中,我有以下错误消息:
Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in /home/dubinfo/www/CRM/model/Locataire.php on line 126
解析错误:第 126 行 /home/dubinfo/www/CRM/model/Locataire.php 中的语法错误、意外的“类”(T_CLASS)、需要标识符(T_STRING)或变量(T_VARIABLE)或“{”或“$”
This is the code :
这是代码:
public function setVisites($visites) {
$this->_visites = CheckTyper::isArrayOfModel($visites,
VisiteMaisonInvestisseur::class, 'visites', __CLASS__);
}
The version of PHP on remote host (OVH) is 5.4.38
远程主机 (OVH) 上的 PHP 版本为 5.4.38
回答by Amir
Using class
as a name of a constant is available in PHP 5.5 only.
使用class
作为常数的名称是在PHP 5.5才可用。
To get the class name you can replace VisiteMaisonInvestisseur::class
with get_class(new VisiteMaisonInvestisseur)
.
要获取类名,您可以替换VisiteMaisonInvestisseur::class
为get_class(new VisiteMaisonInvestisseur)
.
Or change the name of the constant. For example: VisiteMaisonInvestisseur::class_name
.
或者更改常量的名称。例如:VisiteMaisonInvestisseur::class_name
。
回答by Barmar
The problem is with VisitMaisonInvestisseur::class
. class
is a reserved word in PHP, so you can't use it as the name of a constant.
问题在于VisitMaisonInvestisseur::class
. class
是 PHP 中的保留字,因此您不能将其用作常量的名称。
If it works on your local server, it must be version-specific. But I've tested this in 5.3 and 5.6, and they both report an error for Classname::class
.
如果它适用于您的本地服务器,则它必须是特定于版本的。但是我在 5.3 和 5.6 中对此进行了测试,它们都报告了Classname::class
.