#49061 [Opn->Bgs]: Notice Undefined Index for "?:" operator

From: Date: Sun, 26 Jul 2009 21:29:46 +0000
Subject: #49061 [Opn->Bgs]: Notice Undefined Index for "?:" operator
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-140289@lists.php.net to get a copy of this message
ID: 49061 Updated by: rasmus@php.net Reported By: majuki at yahoo dot com -Status: Open +Status: Bogus Bug Type: *General Issues Operating System: CenTOS PHP Version: 5.2.10 New Comment: Once again your script doesn't run. There is a syntax error. Plus, of course you get a warning with: if (!isset($var)) echo $var; The warning is on the echo of a variable that hasn't been set, not on the check itself. Until you provide an actual sensible script that you have run before submitting it, please don't waste any more of our time. Previous Comments: ------------------------------------------------------------------------ [2009-07-26 19:39:14] majuki at yahoo dot com You're right, my mistake - my original script had it more like the following: <?php function doX(){ return 'ok' }; if (!isset($var)) echo $var; if (empty($var)) echo $var; echo (!isset($var)) ? doX() : $var; echo (empty($var)) ? doX() : $var; ?> Both generated the Notice) ------------------------------------------------------------------------ [2009-07-26 19:09:49] rasmus@php.net That is a completely bogus test script. Did you even bother to try running it? You can't have an echo there and you are claiming an undefined index warning in a script that doesn't even have an index. ------------------------------------------------------------------------ [2009-07-26 18:58:03] majuki at yahoo dot com Already included it... but I'll expand on it... <?php function doX(){}; (!isset($var)) ? doX() : echo $var; (empty($var)) ? doX() : echo $var; ?> Above code with E_NOTICE enabled.) ------------------------------------------------------------------------ [2009-07-26 12:02:07] jani@php.net Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with <?php and ends with ?>, is max. 10-20 lines long and does not require any external resources such as databases, etc. If the script requires a database to demonstrate the issue, please make sure it creates all necessary tables, stored procedures etc. Please avoid embedding huge scripts into the report. ------------------------------------------------------------------------ [2009-07-26 03:13:16] majuki at yahoo dot com Description: ------------ A version of this bug was reported last year that was marked bogus (Bug #45760: Notice: Undefined index "?:" operator), however, there is an error in this that is not bogus: (isset($var)) ? doX() : echo $var; (empty($var)) ? doX() : echo $var; These return an undefined index even though it's being checked for. (CentOS) Also note that the notice in legitimate cases is still undocumented on the alternate control structures page. Reproduce code: --------------- (!isset($var)) ? doX() : echo $var; (empty($var)) ? doX() : echo $var; Expected result: ---------------- No "Notice: Undefined index" Actual result: -------------- "Notice: Undefined index" ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=49061&edit=1

« previous php.bugs (#140289) next »