#39166 [Bgs]: array_key_exists() and magic __isset() method with objects

From: Date: Mon, 16 Oct 2006 13:15:15 +0000
Subject: #39166 [Bgs]: array_key_exists() and magic __isset() method with objects
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-103589@lists.php.net to get a copy of this message
 ID:               39166
 User updated by:  peters at yandex dot ru
 Reported By:      peters at yandex dot ru
 Status:           Bogus
 Bug Type:         Class/Object related
 Operating System: Windows and Linux
 PHP Version:      5.1.6
 New Comment:

May be this should be noticed in the manual, because it's not clear
what does mean "also works on objects".


Previous Comments:
------------------------------------------------------------------------

[2006-10-16 13:08:31] tony2001@php.net

ARRAY_key_exists() first converts it to ARRAY and then continues
working, which is expected.

------------------------------------------------------------------------

[2006-10-16 12:57:40] 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


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=39166&edit=1


Thread (3 messages)

« previous php.bugs (#103589) next »