Re: a shortcut to set variable
| From: | David Harkness | Date: | Tue, 12 Apr 2011 19:00:00 +0000 |
| Subject: | Re: a shortcut to set variable | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-312355@lists.php.net to get a copy of this message | ||
On Tue, Apr 12, 2011 at 6:34 AM, Richard Quadling <rquadling@gmail.com>wrote:
> Without running the code, can you say what the output will be in the 3
> examples?
>
Yes, but I would still rewrite that code. ;) I typically reserve the ternary
operator to return a value or assign a variable. Given that it is used less
frequently combined with its precedence in PHP differing from other
languages make using it in complicated expressions prone to errors and
misunderstanding by others.
Adding parentheses avoids interpreter errors but doesn't lessen the
likelihood of another developer breaking the code if they modify it.
David