|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2002-07-07 13:10 UTC] derick@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 01:00:01 2025 UTC |
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.