|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-07-26 03:13 UTC] 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" PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 21 04:00:02 2025 UTC |
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.)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)wow - harsh. Guess you're having a bad day. The code provided, while not my original, does represent the exact syntax that is used and executes as expected. Yes, there's a syntax error, I put the ; in the wrong place when typing it in. I'm sorry for not making it so you can cut and paste, it was a typo. As to my original it is far more complex than this simple extraction and difficult to "sum up" in 10-20 lines. I will attempt to extrapolate the core logic for you and provide cut and paste code. File1: <?php $var = 1; include(file2.php); ?> File2: <div <?php if (empty($var)) echo 'value="' . $var . '"'; ?>></div> <div <?php echo (empty($var)) ? '' : 'value="' . $var. '"'; ?>></div> The above generate the notice where as the following do not: <div <?php if (empty($var)) { echo $var; } ?>></div> <div <?php echo (empty($var)) ? 'value="' . $var. '"' : ''; ?>></div> I hope this is sufficient. Please understand that this is my time too - I'm volunteering my time to report what I've observed to be strange and unexpected behaviour, not because it's a problem I need fixed. All I had to do was turn off E_NOTICE and forget about it, but I thought it might warrant looking into. So please, next time when someone is reporting something, remember that they didn't have to take the time and if they don't have the time (or in some cases the skill) to provide you with perfect code, be a little understanding. I hope tomorrow is a better day for you. Sincerely.)