Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56727 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45207 invoked from network); 2 Dec 2011 17:07:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Dec 2011 17:07:42 -0000 X-Host-Fingerprint: 208.107.21.52 host-52-21-107-208.midco.net Date: Fri, 02 Dec 2011 12:07:42 -0500 Received: from [208.107.21.52] ([208.107.21.52:29608] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 22/74-16911-ED509DE4 for ; Fri, 02 Dec 2011 12:07:42 -0500 Message-ID: <22.74.16911.ED509DE4@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> <9B.03.16911.EB109DE4@pb1.pair.com> <4ED90349.5090308@lerdorf.com> User-Agent: slrn/pre1.0.0-18 (Linux) 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-02, Rasmus Lerdorf wrote: > On 12/02/2011 08:50 AM, Matthew Weier O'Phinney wrote: > > 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. > > But $validator is still going to be defined regardless of the return > value of isValid() so it is going to be set outside the conditional. True. My point was that _semantically_ it looks like it's contained by the conditional. _Technically_, it's not. My main point is that this looks like a pattern folks will try immediately, and wonder why it doesn't work. Whether or not it _should_ work, I'm ambivalent about. I'm more likely to declare and then invoke. -- 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