Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56723 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 38743 invoked from network); 2 Dec 2011 16:50:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Dec 2011 16:50:08 -0000 X-Host-Fingerprint: 208.107.21.52 host-52-21-107-208.midco.net Date: Fri, 02 Dec 2011 11:50:06 -0500 Received: from [208.107.21.52] ([208.107.21.52:13468] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9B/03-16911-EB109DE4 for ; Fri, 02 Dec 2011 11:50:06 -0500 Message-ID: <9B.03.16911.EB109DE4@pb1.pair.com> To: internals@lists.php.net References: <4ED6713D.2050009@ralphschindler.com> <4ED67DCB.5090102@ralphschindler.com> <4ED68940.3050502@ralphschindler.com> <90D867E2-E6FB-481D-B57C-911E5FE6A418@gmail.com> <4ED7BAC2.20805@ralphschindler.com> User-Agent: slrn/pre1.0.0-18 (Linux) Mime-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit X-Posted-By: 208.107.21.52 Subject: Re: [PHP-DEV] 5.4's New De-referencing plus assignment From: weierophinney@php.net (Matthew Weier O'Phinney) On 2011-12-01, Anthony Ferrara wrote: > On Thu, Dec 1, 2011 at 12:34 PM, Ralph Schindler > wrote: > > needs to somehow guarantee that all methods of the type $foo will return > > $this.  (BTW, this is not an argument for my feature as much as its an > > argument as much as its one for "if we're going to do something, why not do > > it correctly in the first place".)  The correct path here, IMO, would be to > > simply carry the expression result (since we're using '(' expr ')' out and > > allow dereferencing on whatever comes out of it. > > > > I would argue though that your syntax is completely possible today: > > $foo = new Foo; > $foo->bar(); > > What's the reason to put that in a single line? Aside from terseness, > is there any other benefit? With the new dereference, one benefit is > that no variable is populated when none is needed. But in your case, > you need both variables... Here's another example. We have validator classes. Typically, you call isValid() to see if a value validates. If it does, you have no more use for the validator. If it _doesn't_, however, you'll want to get the error messages. I could see the following as being a nice, succinct way to use validators: if (!(($validator = new SomeValidator())->isValid($value))) { // Validation failed, get messages... $view->assign('errors' => $validator->getMessages()); return $view->render('error'); } // validation passed, do something... Yes, this could be written as follows: $validator = new SomeValidator(); if (!$validator->isValid($value)) { // ... } // ... However, I can see some folks not really wanting that variable declaration if they won't be using it outside the conditional. -- Matthew Weier O'Phinney Project Lead | matthew@zend.com Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc