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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 17:01:29 2024 UTC