Is there any way to create and use a class named "Array" in PHP? So far, it seems to cause a name conflict with array programming construct, which is not a class.

有帮助吗?

解决方案

The class documentation states:

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

Array is a reserved word and, thus, you cannot. PHP has no way (AFAIK) to "escape" these words. Also see this answer.

You need to name your class more specifically (like MyArray or AnimalList).

其他提示

Here is the list of reserved keywords. It's explicitly said :

These words have special meaning in PHP. Some of them represent things which look like functions, some look like constants, and so on - but they're not, really: they are language constructs.

You cannot use any of the following words as constants, class names, function or method names. Using them as variable names is generally OK, but could lead to confusion.

You've got plenty of alternatives to name your class ;)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top