Re: Late FQCN resolution using ::class

From: Date: Mon, 25 Feb 2013 10:08:08 +0000
Subject: Re: Late FQCN resolution using ::class
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-66180@lists.php.net to get a copy of this message
2013/2/25 Jens Riisom Schultz <ibmurai@me.com> > Hi everybody, > > I have read up on this, and done some testing. > > First up, my findings with PHP5.5 alpha5: > > <?php > namespace spacy; > > class classy { > public static function fqcn() { > /* This works but is not useful enough: */ > //return self::class; > > $me = 'classy'; > > /* This just doesn't work, but I wish it did: */ > //return $me::class; > > /* This simply does not work as expected: */ > return eval("return $me::class;"); > /* Output: "classy" - Expected output: "spacy\classy" */ > } > } > ?> > Without testing anything: My first idea would be 'static::class'. Did you tried this? > > I'm trying to late resolve a class name contained in a variable to the > FQCN. I understand that this is hard (maybe even impossible) with the > current implementation, because class name resolution happens compile time, > but eval("return $me::class;") simply returns something that is weird. > > I guess what I'm trying to ask is whether it would be impossible to > support late FQCN resolution in any way? It would be very useful for > frameworks to be able to do this. > > - Jens Riisom Schultz > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- github.com/KingCrunch

« previous php.internals (#66180) next »