php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #40492 property_exists called in parent class doesn work on private property of subcla
Submitted: 2007-02-15 08:54 UTC Modified: 2007-02-15 09:02 UTC
From: rpg at terry-pratchett dot info Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.1 OS: debian sarge
Private report: No CVE-ID: None
 [2007-02-15 08:54 UTC] rpg at terry-pratchett dot info
Description:
------------
The property_exists function returns true on private properties if called within a class. That doesn't work, if it is called in a function of a parent class. If you overload the function in the childclass it works, but this is actually not the idea behind OOP ;-)

Reproduce code:
---------------
<?
class x {
	private $x;
	public function prop ($p) {
		return property_exists($this,$p);
	}
}
class y extends x {
	private $y;
}
$x = new x;
echo 'prop(x): '.$x->prop('x').'<br>';
$y = new y;
echo 'prop(y): '.$y->prop('y').'<br>';
?>

Expected result:
----------------
you should see
prop(x): 1
prop(y): 1

Actual result:
--------------
prop(x): 1
prop(y): 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-15 09:02 UTC] tony2001@php.net
>If you overload the function in the childclass it
>works, but this is actually not the idea behind OOP

I think inability to access child's private properties from parent's scope is pretty much OO. This is actually how private properties work, they cannot be accessed out of the class scope. 
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 29 05:00:02 2025 UTC