Re: a shortcut to set variable

From: Date: Tue, 12 Apr 2011 21:53:50 +0000
Subject: Re: a shortcut to set variable
References: 1 2 3 4 5 6 7 8  Groups: php.general 
Request: Send a blank email to php-general+get-312356@lists.php.net to get a copy of this message
On 12 April 2011 20:00, David Harkness <david.h@highgearmedia.com> wrote: > 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 > No matter what one developer uses a ternary for, it can be used as in inline if/then/else. And as such, not keeping track of the precedence is what will make for some very interesting debugging exercise. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

« previous php.general (#312356) next »