Ble*_*rer 7 php class function case-sensitive
class List {
public function hello()
{
return "hello";
}
}
$list = new List;
echo $list::hello();
Run Code Online (Sandbox Code Playgroud)
给出错误:
PHP Parse error: syntax error, unexpected 'List' (T_LIST), expecting identifier (T_STRING) in /home/WtGTRQ/prog.php on line 3
Run Code Online (Sandbox Code Playgroud)
将"List"更改为"Lizt"可以解决问题.
我遗憾地理解Php函数不区分大小写,但我真的不想让List对象成为Lizt对象...有没有办法在没有重命名我的类的情况下绕过它?
Nik*_*ola 20
List 是一个受限制的PHP单词.
You cannot use any of the following words as constants, class names, function or method names.
http://www.php.net/manual/en/reserved.keywords.php
-
要回答您的问题,您必须将您的list班级名称更改为其他名称.MyList,CarList,Listing,等.