php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26413 isset of array index of a non-array returns incorrectly
Submitted: 2003-11-25 14:59 UTC Modified: 2003-11-25 17:43 UTC
Votes:3
Avg. Score:4.3 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:2 (66.7%)
From: james at gogo dot co dot nz Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 4CVS OS: *
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2003-11-25 14:59 UTC] james at gogo dot co dot nz
Description:
------------
Using isset to test for the existance of an array index on a non array (in this case string '4') returns true, when plainly, $foo has no element indexed 'bar';


Reproduce code:
---------------
<?php
	$foo = '4';
	if(isset($foo['bar']))
	{
		echo "Uh Oh";
	}
      else
      {
            echo "S'all Good";
      }
?>


Expected result:
----------------
S'all Good

Actual result:
--------------
Uh Oh

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-25 15:08 UTC] sniper@php.net
Works fine with PHP 5 btw. (this fails also with 4.2.3, so this is old issue)

 [2003-11-25 15:38 UTC] iliaa@php.net
This is fixed in PHP 5.0, but for backwards compatibility reasons it'll remain as is in PHP 4.
 [2003-11-25 17:43 UTC] james at gogo dot co dot nz
How is it a compatability problem to fix this?

I don't see how a person would use the incorrect true result for anything useful?  It's seems it would be silly for anything to do anything with the result of that test, as it could mean either the element exists (and isn't null) or the element cannot exist at all (because the variable is not an array).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 07:01:31 2024 UTC