note 12241 deleted from pear.standards.control by zak
| From: | zak@php.net | Date: | Thu, 04 Oct 2001 17:02:46 +0000 |
| Subject: | note 12241 deleted from pear.standards.control by zak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-18576@lists.php.net to get a copy of this message | ||
This page STRONGLY recomends using braces and I agree. But sometime I like to use the following
one-liner for predictably simple situations.
($expression) ? true_action() : default_action() ;
This is the equivilent to the more traditional
if ($expression) {
true_action() ;
} else {
default_action() ;
}
Notice that the first method does not allow for "elseif" case statements. It also does not
allow for empty default statements (do nothing by default). Instead you would use
if ($expression) true_action() ;
//splitting this onto 2 lines would be confusing
But I think PEAR recommends against this. However, I think there are a small few situations where
you know the statement will _always_ be elemental (a single instruction - like a function call).