Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67228 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 60648 invoked from network); 30 Apr 2013 22:25:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Apr 2013 22:25:03 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.128.171 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.128.171 mail-ve0-f171.google.com Received: from [209.85.128.171] ([209.85.128.171:48421] helo=mail-ve0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AB/BB-18873-EB440815 for ; Tue, 30 Apr 2013 18:25:02 -0400 Received: by mail-ve0-f171.google.com with SMTP id oy12so847438veb.16 for ; Tue, 30 Apr 2013 15:24:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type:x-gm-message-state; bh=Je3zEcTekUUn72qFhcOJoiMwxFk1jxQWoQnAk2l+gTI=; b=VrdPsDInsUCFyOuV5gukNftt+auNbL3LTM2me2fA7F93VVdv0Eqzr2XtIZSSxzLxJH 4CHISAEMHFkYcvhrEECbi1epu+CTPw5ZBZCHIZPVP8RpinVCKwcX6BeA84DVXZ3a7upp lk9sWANFA78zCyxU81l9NwSaxMQ1Aas79hlryvkLLKfSmXGLqbd93GrkjdneluQms/E7 462LIaafJk+uGnF6/0wD1PHHLROGNyxpA3ffA6MkyNn6PFsbLI8CeerJPv+xoZby0Qxa vIzjCdvHeJ79KeOPxbZ/NiCRMEj8E6S0wKvimDFTIlGRbCB1GV/LGxhGH0/+T2gVIYOK RBBA== MIME-Version: 1.0 X-Received: by 10.52.93.179 with SMTP id cv19mr109258vdb.20.1367360699224; Tue, 30 Apr 2013 15:24:59 -0700 (PDT) Received: by 10.58.28.134 with HTTP; Tue, 30 Apr 2013 15:24:59 -0700 (PDT) In-Reply-To: <51803086.6020002@sugarcrm.com> References: <6245ED6B-2BF7-47B7-80C0-D3B3D8E0B312@strojny.net> <51803086.6020002@sugarcrm.com> Date: Tue, 30 Apr 2013 18:24:59 -0400 Message-ID: To: Stas Malyshev Cc: PHP internals Content-Type: multipart/alternative; boundary=20cf3071cde2c217d704db9b78df X-Gm-Message-State: ALoCoQkO2HXicoJQicT5wTx9lCibauwlSaMEdJYyS2Xd6ua2sprTceUraoOleZK+5qovuLmbewT8 Subject: Re: [PHP-DEV] property de-referencing From: rasmus@mindplay.dk (Rasmus Schultz) --20cf3071cde2c217d704db9b78df Content-Type: text/plain; charset=ISO-8859-1 Any PHP dev who works with a mainstream framework does this daily, but the frameworks rely on strings for property-names. Take this example from the Symfony manual, for example: class Task { protected $task; protected $dueDate; public function getTask() { return $this->task; } public function setTask($task) { $this->task = $task; } public function getDueDate() { return $this->dueDate; } public function setDueDate(\DateTime $dueDate = null) { $this->dueDate = $dueDate; } } $form = $this->createFormBuilder($task) ->add('task', 'text') ->add('dueDate', 'date') ->getForm(); In this example, 'task' and 'dueDate' are property-references - except of course that, no, they're not - they're obviously just strings... rewriting this example to use a (fictive) form builder API with static property-references: $form = $this->createFormBuilder() ->add(^$task->task, 'text') ->add(^$task->dueDate, 'date') ->getForm(); We now have static property-references, which means the codebase can be proofed using static analysis, which also means better IDE support with property auto-completion, inline documentation, and automatic refactoring for operations like renaming properties, etc. Note that $task need not be passed to createFormBuilder() anymore - instead, we can now use PropertyReference::getObject() inside the form-builder to obtain the instance. For that matter, we can now scrap the form-builder entirely and introduce a simple form-helper in the view instead: Task name: textInput(^$task->task) ?> Due Date: dateInput(^$task->dueDate) ?> This is even better, because we now have the same level of IDE support and static analysis for textInput() and dateInput() which were previously unchecked strings. Or even simpler: Task name: input(^$task->task) ?> Due Date: input(^$task->dueDate) ?> Using PropertyReference::getObject() and reflection inside the form-helper's input() method, we can now use property-annotations to specify the input-type. This is a matter of preference of course, but use of annotations in Symfony is pretty popular. This is just one example - most PHP devs (at least those who do PHP for a living) use form abstractions and object/relational-mappers of some sort, so this has practical applications for practically everyone, everywhere. Rasmus Lerdorf wrote: It is certainly not worth overloading the XOR operator for Are we really going to quibble about syntax? This adds nothing to this discussion. And as I explained earlier, the ^ operator is used for the sake of discussion only - if it's more practical to use another character for this operator, I don't care what it looks like. On Tue, Apr 30, 2013 at 4:58 PM, Stas Malyshev wrote: > Hi! > > > I'm proposing we need a way to statically reference an object property - > > the object property itself, not it's value: > > You probably have use case for that, and it should be pretty easy to > write a class that does that, but why it should be in the language? It > certainly doesn't look like something sizeable portion of PHP devs would > do frequently. > > -- > Stanislav Malyshev, Software Architect > SugarCRM: http://www.sugarcrm.com/ > (408)454-6900 ext. 227 > --20cf3071cde2c217d704db9b78df--