#35870 [Opn->Bgs]: isset() on ternary operator incorrectly evaluates conditions

From: Date: Mon, 02 Jan 2006 07:20:47 +0000
Subject: #35870 [Opn->Bgs]: isset() on ternary operator incorrectly evaluates conditions
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-91332@lists.php.net to get a copy of this message
ID: 35870 Updated by: sniper@php.net Reported By: jevon at jevon dot org -Status: Open +Status: Bogus Bug Type: Scripting Engine problem Operating System: Windows XP PHP Version: 5.1.1 New Comment: 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.. Previous Comments: ------------------------------------------------------------------------ [2006-01-02 05:56:26] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=35870&edit=1

« previous php.bugs (#91332) next »