Bug #16732 Updated: isset() and empty() wrong behavior for empty part of string
| From: | derick@php.net | Date: | Sun, 07 Jul 2002 17:10:45 +0000 |
| Subject: | Bug #16732 Updated: isset() and empty() wrong behavior for empty part of string | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-13403@lists.php.net to get a copy of this message | ||
ID: 16732
Updated by: derick@php.net
Reported By: ssilk@fidion.de
-Status: Open
+Status: Closed
Bug Type: Strings related
Operating System: unix
PHP Version: 4.2.0
New Comment:
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a
documentation
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2002-04-22 11:10:33] ssilk@fidion.de
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 this bug report at http://bugs.php.net/?id=16732&edit=1