note 74622 modified in language.operators.logical by colder

From: Date: Fri, 20 Apr 2007 15:45:17 +0000
Subject: note 74622 modified in language.operators.logical by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-125703@lists.php.net to get a copy of this message
Regardings difference between "||" and "or". 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. --was-- 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. http://php.net/manual/en/language.operators.logical.php

« previous php.notes (#125703) next »