php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53168 'or' and '?:' operators has diferent behaviors
Submitted: 2010-10-26 16:34 UTC Modified: 2010-10-26 16:44 UTC
From: lealcy at gmail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.3.3 OS: Linux version 2.6.35-22-generic-
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: lealcy at gmail dot com
New email:
PHP Version: OS:

 

 [2010-10-26 16:34 UTC] lealcy at gmail dot com
Description:
------------
The test script returns the following:

0 or 2 or 1 => 1
0 ?: 2 ?: 1 => 2
0 or 2 ?: 1 => 1
0 ?: 2 or 1 => 1

Is it desired?

Test script:
---------------
<?php

$a = 0;
$b = 2;
$c = 1;
echo $a.' or '.$b.' or '.$c.' => '; echo $a or $b or $c; echo "<br>\n";
echo $a.' ?: '.$b.' ?: '.$c.' => '; echo $a ?: $b ?: $c; echo "<br>\n";
echo $a.' or '.$b.' ?: '.$c.' => '; echo $a or $b ?: $c; echo "<br>\n";
echo $a.' ?: '.$b.' or '.$c.' => '; echo $a ?: $b or $c; echo "<br>\n";

Expected result:
----------------
0 or 2 or 1 => 2
0 ?: 2 ?: 1 => 2
0 or 2 ?: 1 => 2
0 ?: 2 or 1 => 2

Actual result:
--------------
0 or 2 or 1 => 1
0 ?: 2 ?: 1 => 2
0 or 2 ?: 1 => 1
0 ?: 2 or 1 => 1

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-26 16:44 UTC] felipe@php.net
-Status: Open +Status: Bogus
 [2010-10-26 16:44 UTC] felipe@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

See http://docs.php.net/manual/en/language.operators.logical.php
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 12:01:33 2025 UTC