On 2011-12-02, Rasmus Lerdorf <ras...@lerdorf.com> 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 | matt...@zend.com Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php