Hi!

     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.

Personally, I think the latter code is much better than the former. It makes clear what is created, where, and what the condition is doing, and doesn't require my internal parser to work too hard :)

On the other hand, I don't see a real reason why -> shouldn't be able to be applied to any expression. Yes, sometimes it would be (or seem to me) bad style, so what? It's not like bad style is impossible now ;)
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to