PHP Reserved Words as Namespaces and Class Names

I recently started converting my framework to use php namespaces, and one question I can’t find an answer to is “legally” using reserved words like “Object”, “Array”, 'String' as a namespace and the class name in this namespace? An example is:

namespace System\Object;


class String { }

class Array { }
+2
source share
1 answer

PHP will generate an error, for example:

Parse error: syntax error, unexpected T_ARRAY, expecting T_STRING

if you try:

class Array
{

}
$myClass = new Array;

Instead, try something like

class myArray
{

}
$myClass = new myArray;

[edit] , - , PHP , . , MySQL , , . , PHP , , char , , .

, !

+8

All Articles