#30694 [Asn->WFx]: array_key_exists doesn't work with protected properties
| From: | andi@php.net | Date: | Wed, 17 Nov 2004 01:58:42 +0000 |
| Subject: | #30694 [Asn->WFx]: array_key_exists doesn't work with protected properties | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-69160@lists.php.net to get a copy of this message | ||
ID: 30694
Updated by: andi@php.net
Reported By: guth at fiifo dot u-psud dot fr
-Status: Assigned
+Status: Wont fix
Bug Type: Zend Engine 2 problem
Operating System: Linux
PHP Version: 5.0.2
Assigned To: andi
New Comment:
I don't think this is a bug. In general, ZEII makes a much clearer
destinction between objects and arrays. The conversion between them is
still defined for BC reasons. I think defining the conversion to mean
that only public variables will be in the resulting array is fair and
makes sense as array's have no sense of access modifiers *and* it
doesn't break BC as protected doesn't exist in PHP 4.
Previous Comments:
------------------------------------------------------------------------
[2004-11-09 17:16:08] tony2001@php.net
Assigning to Andi.
But I'd like to add that using objects as arrays of properties should
be deprecated IMO, as there are plenty of functions respecting scope
(see get_object_vars(), for example) and personally I do not see any
sense in duplicating their functionality.
------------------------------------------------------------------------
[2004-11-05 17:40:36] guth at fiifo dot u-psud dot fr
Description:
------------
Hello,
array_key_exists should return true for protected and
private vars if the are called from that scope.
Bad english to explain more, so look at the code.
Vincent Guth
Reproduce code:
---------------
<?php
class A {
protected $b = 'test';
public $c = 'test';
public function __construct() {
var_dump(array_key_exists('b', $this));
var_dump(array_key_exists('c', $this));
}
}
new A;
?>
Expected result:
----------------
bool(true)
bool(true)
Actual result:
--------------
bool(false)
bool(true)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=30694&edit=1