php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35870 isset() on ternary operator incorrectly evaluates conditions
Submitted: 2006-01-02 05:56 UTC Modified: 2006-01-02 08:20 UTC
From: jevon at jevon dot org Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.1.1 OS: Windows XP
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: jevon at jevon dot org
New email:
PHP Version: OS:

 

 [2006-01-02 05:56 UTC] jevon at jevon dot org
Description:
------------
I'm not sure if this has been submitted before, because it's a bit difficult to search for 'isset' on bugs.php.net.

Basically if you have isset() in a ternary operation (?:), PHP currently evaluates all items in the operation, whereas it shouldn't. I guess this is because isset() is a language construct.

Reproduce code:
---------------
<?php
$x = array();
if (isset($x[1]))
	echo $x[1];
else
	echo 0;

echo isset($x[1]) ? 0 : $x[1];
?>

Expected result:
----------------
0
0

Actual result:
--------------
0
PHP Notice: Undefined offset: 1 in test.php on line 8

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-02 08:20 UTC] sniper@php.net
Please read again how ternary operator works. 
hint1: isset($x[1]) == false
hint2: when condition in ternary operation evaluates to false, the stuff after : is executed..
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sat Jun 20 07:00:01 2026 UTC