php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30694 array_key_exists doesn't work with protected properties
Submitted: 2004-11-05 17:40 UTC Modified: 2004-11-17 02:58 UTC
From: guth at fiifo dot u-psud dot fr Assigned: andi (profile)
Status: Wont fix Package: Scripting Engine problem
PHP Version: 5.0.2 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2004-11-05 17:40 UTC] 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) 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-09 17:16 UTC] 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-17 02:58 UTC] andi@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 06:01:28 2024 UTC