Re: Enhanced __CLASS__ constant

From: Date: Wed, 21 Jan 2009 21:41:16 +0000
Subject: Re: Enhanced __CLASS__ constant
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-42757@lists.php.net to get a copy of this message
Hey! First of all: the idea is very good. Criticism: Again, that's a new Syntax "feature"; May we deploy this into next releases of PHP? Thanks! -- (c) Kenan Sulayman Freelance Designer and Programmer Life's Live Poetry 2009/1/21 David Grudl <david@grudl.com> > Especially in namespaced code it should be very useful to have "something" > returning fully qualified name as string. It can be operator, but I think > introducing new keyword is bad way, or it can be realized using well known > magic constant in new context: > > Example: > > function factory($class) > { > return new $class; > } > > $obj = factory('MyClass'); // returns object MyClass > $obj = factory(MyClass::__CLASS__); // returns again object MyClass, code > is little bit more selfexplaining > > > But big advantages are in namespaced code (especially when you refactor a > code): > > namespace Foo; > use Other\Bar; > > $obj = factory('MyClass'); // ERROR - returns object \MyClass, must be > refactored to: > $obj = factory(__NAMESPACE__ . '\\MyClass'); // very very ugly! :-( > $obj = factory('Other\Bar'); // use statement must be duplicated here :-( > > // with magic contant: > $obj = factory(MyClass::__CLASS__); // returns object Foo\MyClass, very > understandable :-) > $obj = factory(Bar::__CLASS__); // returns object Other\Bar, as use > statement declares :-) > > David Grudl > > > > > > > > > > > > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.internals (#42757) next »