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.
-Rasmus
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php