From: [EMAIL PROTECTED] Operating system: unix PHP version: 4.2.0 PHP Bug Type: Strings related Bug description: isset() and empty() wrong behavior for empty part of string
The following program displays a notice (error_reporting is set to display all warnings): ------------- <pre> <?php $a='hugp'; for ($i=0; isset($a[$i]); $i++) { echo "\nChar $i:$a[$i]"; } ?> ------------- Displays the message Notice: Uninitialized string offset: 4 ... line 4 This is a bug, cause isset() is used to determine, if $a[4] is set or not, so there has to be no message, that a var is not set. It happens also, if you write $a{$i} instead of $a[$i] (this is the syntax, which will only be supported from PHP5 up). Cause isset() is used in empty(), empty has also this bug. This bug has already been reported (#16528), but has been closed - perhaps due to completly other example (array depending). I have been told that it's not a bug. But as you directly see with this example it is. I have written a mail to Derick Redhans who cleaned it, that it might be a fault to clean it, but never heard an answer. Please fix this bug, cause programmers, who write the following: $a=''; if ( !empty($a['bla']) ) will be complained with this Notice, even it is correct code (and maybe that, what he wants). Of course it is correct to display the notice, if you write: echo $a['bla']; --------- A small suggestion: Cause Zeev said on PHP-Congress, that the above syntax (with [] instead of {}) to exercise a char in a string is not supported any more in PHP5, it might be a very good idea to implement a switch, which will warn if you use the syntax right now! This switch could also be used, to warn the programmer for other incompatibilities... with PHP5. -- Edit bug report at http://bugs.php.net/?id=16732&edit=1 -- Fixed in CVS: http://bugs.php.net/fix.php?id=16732&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=16732&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=16732&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=16732&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=16732&r=support Expected behavior: http://bugs.php.net/fix.php?id=16732&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=16732&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=16732&r=submittedtwice