开发者

How to define a class with same name as built-in function?

开发者 https://www.devze.com 2023-04-10 05:45 出处:网络
I would like to define a class named \"List\" like this: class List { } PHP gives the following error at the file of the class definition: \"Parse error: 开发者_如何学Csyntax error, unexpected T_LI

I would like to define a class named "List" like this:

class List
{
}

PHP gives the following error at the file of the class definition: "Parse error: 开发者_如何学Csyntax error, unexpected T_LIST, expecting T_STRING"

Apparently there is a php built-in function named "list()" that the parser is reading here instead of my class definition even though the line starts with the keyword class

Since I don't use the built-in function anywhere in my project I would like to "remove/disable" it, so I can use my class named "List".

Is this possible in php and how?


list is a reserved word as it is a language construct (not actually a function), so no, you cannot disable it. Try being more specific with your class name, e.g., ObjectList or AbstractList.


The class name can be any valid label which is a not a PHP reserved word.

List of PHP reserved words says list is one of those words.

0

精彩评论

暂无评论...
验证码 换一张
取 消