Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67288 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87212 invoked from network); 3 May 2013 08:25:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 May 2013 08:25:12 -0000 Authentication-Results: pb1.pair.com smtp.mail=linepogl@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=linepogl@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.169 as permitted sender) X-PHP-List-Original-Sender: linepogl@gmail.com X-Host-Fingerprint: 209.85.214.169 mail-ob0-f169.google.com Received: from [209.85.214.169] ([209.85.214.169:60777] helo=mail-ob0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 78/80-17534-76473815 for ; Fri, 03 May 2013 04:25:12 -0400 Received: by mail-ob0-f169.google.com with SMTP id tb18so1237123obb.0 for ; Fri, 03 May 2013 01:25:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=gwElp6jV6xt2JOvJixe99LD9eATg454NdUn0R79PXHE=; b=MJsIMuIUMzzfzjfVUwY+nPN8m7wZa1pv/a782Yb6/3dYJV+Di+9e/13Fjh79h61lhQ yTqr+kj7pz/0Gq0oG3Nq5Ufpfzk//JeLPiY3I2uG00NANnzG4yyq1a7uBLYQf9zC82Xi fCPNXIox23lXbuc5Omaz087pVqisSeRqwCUkleWmdxEQbfMIjDiZwkgJaNYi8A9mdZ5c zex/rjMN6aNwBlGftwOu/Ie2h/y3YWENreVxqG+Ljl0DIqK2aLI7A/dtMvvpZo6UAS8o tRmvddUP1aX+jcyXPsc8NKS33gtDVaw9NemYQuDMsaSJD/Y9pH/OW5HnIdhOd4UVACSm f/zg== X-Received: by 10.60.121.33 with SMTP id lh1mr2637678oeb.98.1367569509377; Fri, 03 May 2013 01:25:09 -0700 (PDT) MIME-Version: 1.0 Received: by 10.76.154.130 with HTTP; Fri, 3 May 2013 01:24:49 -0700 (PDT) In-Reply-To: References: <6245ED6B-2BF7-47B7-80C0-D3B3D8E0B312@strojny.net> <51803086.6020002@sugarcrm.com> <518030FD.5030504@lerdorf.com> Date: Fri, 3 May 2013 10:24:49 +0200 Message-ID: To: Bernhard Schussek Cc: Rasmus Schultz , Adam Harvey , PHP internals Content-Type: multipart/alternative; boundary=047d7b33d004d039f204dbcc1632 Subject: Re: [PHP-DEV] property de-referencing From: linepogl@gmail.com (Lazare Inepologlou) --047d7b33d004d039f204dbcc1632 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 2013/5/2 Bernhard Schussek > 2013/5/1 Rasmus Schultz > > > > 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 suggest= s > > > 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 indirectio= n > 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 abstra= ct > 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=C3=A9nieur Logiciel --047d7b33d004d039f204dbcc1632--