Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67269 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18064 invoked from network); 2 May 2013 13:07:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 May 2013 13:07:30 -0000 Authentication-Results: pb1.pair.com header.from=bschussek@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=bschussek@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.172 as permitted sender) X-PHP-List-Original-Sender: bschussek@gmail.com X-Host-Fingerprint: 74.125.82.172 mail-we0-f172.google.com Received: from [74.125.82.172] ([74.125.82.172:46583] helo=mail-we0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5D/95-06131-01562815 for ; Thu, 02 May 2013 09:07:29 -0400 Received: by mail-we0-f172.google.com with SMTP id s10so462607wey.3 for ; Thu, 02 May 2013 06:07:26 -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=3NdLVkOjbALveEiv94VLDspCHNHPEnKQdI0nQhUfhGs=; b=Ox0D7jiTF/RWu5eAU1HLK/cI+6bpfRp9FM6Eqzli3GTBL7N0ym2h/i83S+TN4xakeH Y+BqzUmohztjCWMRZ6lONVz1SHJdvQa//Rw/dZZ474g2uodi3kvTS6zxTYHSgM3jy5Fk akc6ZiwUeD3OKn776R3ilEj+u96dKux2WrS7QaTV8w+ACgeGgOz8uPdEKJlXGm6hAboG 79IV0Z+D4jbCQyjZbCB95CZnzJYD31L0DKJNL3vR2JpUu/yTu/xkRD/6WdhGkoSNwy8Q orJeSoE+WoaxYx5Tt12MHhtvA+f/+K8Fz9hXdEFS5DM23WQBlV365VonWaiTvPN2PdKq zHgA== X-Received: by 10.180.105.231 with SMTP id gp7mr1358111wib.23.1367500046206; Thu, 02 May 2013 06:07:26 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.55.230 with HTTP; Thu, 2 May 2013 06:06:55 -0700 (PDT) In-Reply-To: References: <6245ED6B-2BF7-47B7-80C0-D3B3D8E0B312@strojny.net> <51803086.6020002@sugarcrm.com> <518030FD.5030504@lerdorf.com> Date: Thu, 2 May 2013 15:06:55 +0200 Message-ID: To: Rasmus Schultz Cc: Adam Harvey , PHP internals Content-Type: multipart/alternative; boundary=f46d0442881a7c0db104dbbbeaf6 Subject: Re: [PHP-DEV] property de-referencing From: bschussek@gmail.com (Bernhard Schussek) --f46d0442881a7c0db104dbbbeaf6 Content-Type: text/plain; charset=UTF-8 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 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'] etc., depending on whether accessors exist or the properties themselves are public (also works for writing values). This is a concept borrowed from Java and known as "property paths". [2] Without the possibility of chaining, property references are useless IMO. Cheers, Bernhard [1] http://symfony.com/doc/current/components/property_access/introduction.html [2] http://static.springsource.org/spring-data/data-commons/docs/1.3.0.M1/api/org/springframework/data/mapping/PropertyPath.html --f46d0442881a7c0db104dbbbeaf6--