문제

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