尝试创建一个名为“List”的类,但list()函数会打破它 [英] Trying to make a class called "List", but the list() function is breaking it

查看:622
本文介绍了尝试创建一个名为“List”的类,但list()函数会打破它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  class List {
public function hello()
{
returnhello;
}
}

$ list = new List;

echo $ list :: hello();

发生错误

  PHP解析错误:语法错误,意外的'List'(T_LIST),期望标识符(T_STRING)在/home/WtGTRQ/prog.php第3行

将列表更改为Lizt可修复此问题。



我很遗憾地了解到 Php函数不区分大小写,但我真的不想要使List对象成为一个Lizt对象...有没有一些方法可以绕过这个没有重命名我的类?

解决方案

code>列表是受限的PHP字。



您不能使用以下任何字词作为常量,类名,函数或方法名。



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



-



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

class List {
  public function hello()
  {
    return "hello";
  }
}

$list = new List;

echo $list::hello();

Gives Error:

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

Changing "List" to "Lizt" fixes the issue.

I sadly understand that Php functions are case-insensitive, but I really don't want to make a List object a Lizt object... Is there some way to circumvent this without renaming my class?

解决方案

List is a restricted PHP word.

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

--

To answer your question, you will have to change your list class name to something else. MyList, CarList, Listing, etc..

这篇关于尝试创建一个名为“List”的类,但list()函数会打破它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆