Re: property de-referencing

From: Date: Tue, 30 Apr 2013 23:34:39 +0000
Subject: Re: property de-referencing
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On 30 April 2013 16:15, Rasmus Schultz <[email protected]> wrote:
> At the risk of starting a separate discussion, the recently added
> ClassName::class constant provides a way to statically reference a class,
> which frankly has very few practical applications in comparison - the need
> to reference properties is usually much more prevalent and repetitive than
> the need to reference a class; assuming your classes have more than one
> property each, heh. The feature as such is also somewhat crippled, since
> what comes out of it is a string and not a class-reference.

I would caution against generalising use cases. Personally, ::class is
something I can use multiple times a day. This I'm not so sure about.

Your use case is not my use case, and vice versa. :)

> I think there is still a pretty strong case for static property-references,
> but since any new language-feature is generally a pretty hard sell around
> here, I'm letting this one go for now.

Why does this have to be a language feature? It obviously already
works in userland, as your own Symfony 2 examples show. One could
write a PropertyReference class right now with literally the only
difference being the lack of a builtin operator (ie new
PropertyReference($obj, 'prop') versus ^$obj->prop): the fact that
nobody seems to have done this in a major framework I know of suggests
that there isn't a strong need for encapsulating the indirection
beyond the $obj->$prop syntax that's worked forever.

Adam


Thread (64 messages)

« previous php.internals (#67232) next »