php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44252 ? : evaluation bug
Submitted: 2008-02-26 12:35 UTC Modified: 2008-02-26 12:57 UTC
From: OlafvdSpek at GMail dot Com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.2.5 OS: Linux, Windows
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: OlafvdSpek at GMail dot Com
New email:
PHP Version: OS:

 

 [2008-02-26 12:35 UTC] OlafvdSpek at GMail dot Com
Description:
------------
The following code echoes 3 while it should echo 2.
It should be evaluated as 1 ? 2 : (0 ? 3 : 4). I've no idea how PHP comes up with 3.

Reproduce code:
---------------
echo 1 ? 2 : 0 ? 3 : 4;

Expected result:
----------------
2

Actual result:
--------------
3

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-26 12:47 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

This is documented.
See the example#3:
http://docs.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary
 [2008-02-26 12:57 UTC] OlafvdSpek at GMail dot Com
Ah, so it's evaluated as (1 ? 2 : 0) ? 3 : 4
Nice, very nice. :(
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Aug 07 03:00:03 2025 UTC