RFC: about class names as values

From: Date: Thu, 06 Jan 2011 00:53:56 +0000
Subject: RFC: about class names as values
Groups: php.internals 
Request: Send a blank email to internals+get-51228@lists.php.net to get a copy of this message
Hi all, RFC: about class names as values PHP uses class names as values, but only in a couple of places. String constanst after the "new" or "instanceof" operator --correct me if I'm missing others-- are treated as class names. if( $obj instanceof MyClass ) { // $obj is instanceof Bar/Foo/MyClass } but what happen if the class name is used on other places? function newInstance($class) { return new $class; } $obj = newInstance( MyClass ); // notice. undefined constant MyClass so you have to end up by writting.... $obj = newInstance( '\Bar\Foo\MyClass' ); which lacks of any semantic, it's not a class name, it's just a string. My idea is that PHP could include a constant on each class, a string with the full qualified class name echo MyClass::CLASS; // \Bar\Foo\MyClass $obj = newInstance( MyClass::CLASS ); As the "CLASS" is currently a reserved word is guarantied that nobody is using as it today. What do you think about? Martin Scotta

« previous php.internals (#51228) next »