加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 16:01:23 所属栏目:PHP教程 来源:网络整理
导读:class List { public function hello() { return "hello"; }}$list = new List;echo $list::hello(); 给出错误: PHP Parse error: syntax error,unexpected 'List' (T_LIST),expecting identifier (T_STRING) in /home/WtGTRQ/prog.php on line 3 将“List
class List {
  public function hello()
  {
    return "hello";
  }
}

$list = new List;

echo $list::hello();

给出错误:

PHP Parse error: syntax error,unexpected 'List' (T_LIST),expecting identifier (T_STRING) in /home/WtGTRQ/prog.php on line 3

将“List”更改为“Lizt”可以解决问题.

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

List是受限制的PHP单词.

您不能将以下任何单词用作常量,类名,函数或方法名称.

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读