|
Posted by Martin Lucas-Smith on 12/21/05 14:06
On Wed, 21 Dec 2005, tony@marston-home.demon.co.uk wrote:
> > So, PHP makers, if you are reading this:
> Please, please, please, *PLEASE* drop the ternary operator from future
> PHP versions! Just read the legacy code I'm confronted with and you
> understand why.
>
> Now there I would agree 100%. Every time I see the ternary operator I
> want to puke.
Why? Once you know it exists, it makes coding certain things very much
more efficient, e.g.
echo "You have $total " . (count ($total) == 1 ? 'item' : 'items') . '.';
rather than the verbose
if (count ($total) == 1) {
$tempWord = 'item';
} else {
$tempWord = 'items';
}
echo "You have $total {$tempWord}.";
unset ($tempWord);
or
$foo = (isSet ($_GET['foo']) ? $_GET['foo'] : 'default');
It's not as if this construct only exists in PHP.
Martin
Navigation:
[Reply to this message]
|