php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52694 Or operator inconsistency
Submitted: 2010-08-25 09:11 UTC Modified: 2010-08-25 09:24 UTC
From: biolizard dot mail at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.3 OS: Linux Fedora 13
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: biolizard dot mail at gmail dot com
New email:
PHP Version: OS:

 

 [2010-08-25 09:11 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-25 09:14 UTC] rasmus@php.net
-Status: Open +Status: Bogus
 [2010-08-25 09:14 UTC] 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:24 UTC] biolizard dot mail at gmail dot com
I apologize for the inconvenience.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 01:01:28 2025 UTC