note 49666 added to language.expressions
| From: | tom at darlingpet dot com | Date: | Fri, 04 Feb 2005 10:13:24 +0000 |
| Subject: | note 49666 added to language.expressions | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-84504@lists.php.net to get a copy of this message | ||
Something I've noticed with ternary expressions is if you do something like :
<?= $var=="something" ? "is something" : "not something"; ?>
It will give wacky results sometimes...
So be sure to enclose the ternary expression in parenthesis when ever necessary (such as having
multiple expressions or nested ternary expressions)
The above could look like:
<?= ($var=="something") ? "is something" : "not something"; ?>
It's also a good idea to use parenthesis when using something SIMILAR to:
<?php
echo (trim($var)=="") ? "empty" : "not empty";
?>
In some cases other than the <?= ?> example, not placing the entire expression in appropriate
parenthesis might yield undesirable results as well.. but I'm not quite sure.
----
Manual Page -- http://www.php.net/manual/en/language.expressions.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49666
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49666&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49666&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49666&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49666&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49666&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49666&report=yes
Search -- http://master.php.net/manage/user-notes.php