Bug #52694 [Bgs]: Or operator inconsistency
| From: | biolizard dot mail at gmail dot com | Date: | Wed, 25 Aug 2010 07:24:36 +0000 |
| Subject: | Bug #52694 [Bgs]: Or operator inconsistency | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-153776@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52694&edit=1
ID: 52694
User updated by: biolizard dot mail at gmail dot com
Reported by: biolizard dot mail at gmail dot com
Summary: Or operator inconsistency
Status: Bogus
Type: Bug
Package: Scripting Engine problem
Operating System: Linux Fedora 13
PHP Version: 5.3.3
Block user comment: N
New Comment:
I apologize for the inconvenience.
Previous Comments:
------------------------------------------------------------------------
[2010-08-25 09:14:21] rasmus@php.net
It follows the operator precedence rules documented here:
http://php.net/manual/en/language.operators.precedence.php
OR and || are obviously not synonymous. Your examples match the
documented
precedence table.
------------------------------------------------------------------------
[2010-08-25 09:11:13] biolizard dot mail at gmail dot com
Description:
------------
The logical operator 'or' and the operator '||' produce different
values, which
is inconsistent with the description and the examples presented in the
PHP
website. However, when returning from a function, the inconsistency is
even more
problematic. The operator 'or', when used in a statement (e.g.,
assignment),
returns the first value that is not false. However, when used as a
return
expression the returned value is either true or false.
Test script:
---------------
<?php
function f() {
return 'ola' || 'adeus';
}
function p() {
return 'ola' or 'adeus';
}
$a = 'ola' || 'adeus';
$b = 'ola' or 'adeus';
echo $a . "\n";
echo $b . "\n";
echo f() . "\n";
echo p() . "\n";
?>
Expected result:
----------------
1
ola
1
ola
Actual result:
--------------
1
ola
1
1
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52694&edit=1