note 74622 added to language.operators.logical
| From: | /Life at osu1 dot php dot net | Date: | Fri, 20 Apr 2007 15:40:37 +0000 |
| Subject: | note 74622 added to language.operators.logical | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-125702@lists.php.net to get a copy of this message | ||
Regardings the post of g dot vieri AT gmail dot com:
It's actually the precedence that causes this effect:
<?php
$res = $a || $b;
# is the same as
$res = ($a || $b);
?>
$a is true in this case, hence $res is true (short circuit).
<?php
$res = $a or $b;
# is the same as
($res = $a) or $b;
?>
The value of the assignment is the assigned value itself, which is 'test' (as is the new
value of $res). Since 'test' evaluates to true as well, $b isn't executed anymore
(short circuit, just as above) - besides: $b is a statement without any effect anyway.
----
Server IP: 129.16.214.50
Probable Submitter: 212.202.36.235
----
Manual Page -- http://www.php.net/manual/en/language.operators.logical.php
Edit -- https://master.php.net/note/edit/74622
Del: integrated -- https://master.php.net/note/delete/74622/integrated
Del: useless -- https://master.php.net/note/delete/74622/useless
Del: bad code -- https://master.php.net/note/delete/74622/bad+code
Del: spam -- https://master.php.net/note/delete/74622/spam
Del: non-english -- https://master.php.net/note/delete/74622/non-english
Del: in docs -- https://master.php.net/note/delete/74622/in+docs
Del: other reasons-- https://master.php.net/note/delete/74622
Reject -- https://master.php.net/note/reject/74622
Search -- https://master.php.net/manage/user-notes.php