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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 01:01:28 2024 UTC