note 94232 added to language.operators.logical
| From: | Rob at osu1 dot php dot net | Date: | Fri, 23 Oct 2009 17:16:13 +0000 |
| Subject: | note 94232 added to language.operators.logical | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-162024@lists.php.net to get a copy of this message | ||
Another example that might help.
<?php
(isset($panelemail) && !empty($panelemail) ? $panelemail : $userdata['email']);
?>
returns the userdata email address, but this
<?php
(isset($panelemail) AND !empty($panelemail) ? $panelemail : $userdata['email']);
?>
returns false.
The reason is that the two types of ands have a different order of precedence.
"&&" is higher than "AND", and the "?:" operator just happens
to come between the two. Also, since "||" (or) is actually higher than "AND,"
you should never mix &&s and ||s with ANDs and ORs without paretheses.
For example:
<?php
true && false || false
?>
returns false, but
<?php
true AND false || false
?>
returns true.
----
Server IP: 64.71.164.2
Probable Submitter: 24.153.133.114
----
Manual Page -- http://www.php.net/manual/en/language.operators.logical.php
Edit -- https://master.php.net/note/edit/94232
Del: integrated -- https://master.php.net/note/delete/94232/integrated
Del: useless -- https://master.php.net/note/delete/94232/useless
Del: bad code -- https://master.php.net/note/delete/94232/bad+code
Del: spam -- https://master.php.net/note/delete/94232/spam
Del: non-english -- https://master.php.net/note/delete/94232/non-english
Del: in docs -- https://master.php.net/note/delete/94232/in+docs
Del: other reasons-- https://master.php.net/note/delete/94232
Reject -- https://master.php.net/note/reject/94232
Search -- https://master.php.net/manage/user-notes.php