Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67234 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73021 invoked from network); 30 Apr 2013 23:50:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Apr 2013 23:50:40 -0000 Authentication-Results: pb1.pair.com header.from=krebs.seb@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=krebs.seb@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.174 as permitted sender) X-PHP-List-Original-Sender: krebs.seb@gmail.com X-Host-Fingerprint: 74.125.82.174 mail-we0-f174.google.com Received: from [74.125.82.174] ([74.125.82.174:63598] helo=mail-we0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2C/FD-18873-FC850815 for ; Tue, 30 Apr 2013 19:50:40 -0400 Received: by mail-we0-f174.google.com with SMTP id t9so886310wey.5 for ; Tue, 30 Apr 2013 16:50:37 -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=7YuHxvtxt/TfwIVHqLYwivkNzp4GzpnGWQ26WjqRe7Q=; b=nt5QUw7vtwr5dNq04cyjJsVi3c59HlYLnqdDffMAFQt9rD5i4m2bkNDpaszu/mEhhO //8Jhmpm+H19aLITAfgtcABgJPhxy0isSqXufke99JtAmd7ElC6Phqo7okL0ENfD+b8F WWVKwg4DNItNDZJI6NUs7z33JZtPGtrlvAzDjcdW715Jn57zYqfrC7lTEWB5v1tyB3om c14EJ7MXYl16wgowQMMxomKcSE//6VqyOSr6lbMqo1hCVbe4K6YPjd2Ai4x8OgSIvdBu CDSCNU3oFAEmT7P79EbhzrmHFQq3J+Hg3R1KSPNDZVCrftKbaFxpSqlYxuCuiMcp+Kng uXFw== X-Received: by 10.181.13.74 with SMTP id ew10mr538227wid.9.1367365837425; Tue, 30 Apr 2013 16:50:37 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.43.72 with HTTP; Tue, 30 Apr 2013 16:50:17 -0700 (PDT) In-Reply-To: References: <6245ED6B-2BF7-47B7-80C0-D3B3D8E0B312@strojny.net> <51803086.6020002@sugarcrm.com> Date: Wed, 1 May 2013 01:50:17 +0200 Message-ID: To: Rasmus Schultz Cc: Stas Malyshev , PHP internals Content-Type: multipart/alternative; boundary=f46d043c7dde04943504db9cab1b Subject: Re: [PHP-DEV] property de-referencing From: krebs.seb@gmail.com (Sebastian Krebs) --f46d043c7dde04943504db9cab1b Content-Type: text/plain; charset=ISO-8859-1 2013/5/1 Rasmus Schultz > 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(); > One problem I have with this example is, that you usually (or at least often) don't have a "$task" object here. > > 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 > > > -- github.com/KingCrunch --f46d043c7dde04943504db9cab1b--