php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39166 array_key_exists() and magic __isset() method with objects
Submitted: 2006-10-16 12:57 UTC Modified: 2006-10-16 13:15 UTC
From: peters at yandex dot ru Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.1.6 OS: Windows and Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: peters at yandex dot ru
New email:
PHP Version: OS:

 

 [2006-10-16 12:57 UTC] peters at yandex dot ru
Description:
------------
array_key_exists() may take object as second parameter and
in such case I think it should use __isset() magic function of the object (if any), but it seems not to do so.
The  isset() and array_key_exists() may return different results for the same object, which is not good :)

Reproduce code:
---------------
class TestObject
{
	function __isset($nm)
	{
		return true;
	}
}

$A = new TestObject();

var_dump(array_key_exists('test', $A));
var_dump(isset($A->test));

Expected result:
----------------
true
true

Actual result:
--------------
false
true

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-16 13:08 UTC] tony2001@php.net
ARRAY_key_exists() first converts it to ARRAY and then continues working, which is expected.
 [2006-10-16 13:15 UTC] peters at yandex dot ru
May be this should be noticed in the manual, because it's not clear what does mean "also works on objects".
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 13 07:01:26 2025 UTC