That's an interesting spin on the idea, but it takes away the ability to
lazy-evaluate an entire path - now it works only for the last property,
which may not always be optimal or desirable.

I don't personally have a problem with putting the operator before the
expression, I think that's clear enough - it's clear enough for the // and
# comment operators, for example, that the entire line will be commented
out.

If you don't agree with that, maybe it should be a grouping operator, e.g.
a start and an end symbol? Even harder to find characters that won't
conflict though...

On Fri, May 3, 2013 at 4:24 AM, Lazare Inepologlou <linep...@gmail.com>wrote:

>
>
> 2013/5/2 Bernhard Schussek <bschus...@gmail.com>
>
>> 2013/5/1 Rasmus Schultz <ras...@mindplay.dk>
>>
>> >  > 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.
>> > >
>> >
>> > Look at the Symfony form-builder example - encapsulating the
>> indirection is
>> > *precisely* what they're doing: the object reference is stored in the
>> > form-builder, and property-names are added subsequently.
>> >
>>
>> As the developer of the Symfony Form component, I would like to clarify
>> that this is not true. At the time the property reference is stored, the
>> object it refers to is not (necessarily) known. You could build an
>> abstract
>> form definition for "Author" instances, but only later instantiate a form
>> for that definition with a concrete object. So to be really useful in a
>> form context, property references need to be separated from object
>> instances (something like "^Author::$firstName" could work).
>>
>> Second, it is important that references can span multiple nodes in an
>> object/array graph. In Symfony, we built the PropertyAccess component for
>> that [1] which allows references like
>>
>> "authors[0].personalDetails[firstName]"
>>
>> which translates to
>>
>> ->getAuthors()[0]->getPersonalDetails()['firstName']
>>
>> or
>>
>> ->authors[0]->getPersonalDetails()['firstName']
>>
>>
>
> I have an idea regarding the syntax. The suggested ^ operator is
> troublesome, because it does not make clear that whatever follows will not
> be evaluated. This becomes even more confusing when dealing with multiple
> nodes, as the example above, where part of the expression has to be
> evaluated.
>
> Let's have something different:
>
>   $obj~>property
>   MyClass::~property
>
>
> This syntax can be easily applied to multiple nodes, without confusion:
>
>   ->getAuthors()[0]->getPersonalDetails()~>firstName
>
> And it can be applied statically:
>
>   Author::~firstName
>
>
>
>
> Lazare Inepologlou
> Ingénieur Logiciel
>
>

Reply via email to