php – 尝试创建一个名为“List”的类,但list()函数正在打破它

前端之家收集整理的这篇文章主要介绍了php – 尝试创建一个名为“List”的类,但list()函数正在打破它前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. class List {
  2. public function hello()
  3. {
  4. return "hello";
  5. }
  6. }
  7.  
  8. $list = new List;
  9.  
  10. echo $list::hello();
@H_301_3@给出错误

  1. PHP Parse error: Syntax error,unexpected 'List' (T_LIST),expecting identifier (T_STRING) in /home/WtGTRQ/prog.PHP on line 3
@H_301_3@将“List”更改为“Lizt”可以解决问题.

@H_301_3@我遗憾地理解Php functions are case-insensitive,但我真的不想让List对象成为一个Lizt对象…有没有办法绕过这个而不重命名我的类?

List是受限制的PHP单词. @H_301_3@您不能将以下任何单词用作常量,类名,函数方法名称.

@H_301_3@http://www.php.net/manual/en/reserved.keywords.php

@H_301_3@ –

@H_301_3@要回答您的问题,您必须将列表类名称更改为其他名称. MyList,CarList,Listing等.

猜你在找的PHP相关文章