php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16732 isset() and empty() wrong behavior for empty part of string
Submitted: 2002-04-22 11:10 UTC Modified: 2002-07-07 13:10 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: ssilk at fidion dot de Assigned:
Status: Closed Package: Strings related
PHP Version: 4.2.0 OS: unix
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ssilk at fidion dot de
New email:
PHP Version: OS:

 

 [2002-04-22 11:10 UTC] ssilk at fidion dot 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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-07 13:10 UTC] derick@php.net
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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 03:01:27 2024 UTC