Bug #66670 [Nab]: property_exist cannot find private properties defined in superclass

From: Date: Mon, 10 Feb 2014 23:11:01 +0000
Subject: Bug #66670 [Nab]: property_exist cannot find private properties defined in superclass
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184246@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66670&edit=1 ID: 66670 User updated by: mpope at homeimprovementleads dot com Reported by: mpope at homeimprovementleads dot com Summary: property_exist cannot find private properties defined in superclass Status: Not a bug Type: Bug Package: Class/Object related Operating System: windows 7 PHP Version: 5.5.9 Block user comment: N Private report: N New Comment: Ok, but there is still a bug in that if you call property_exists from the class proper, vs from some externally defined method from the class you get different results. In the example I posted, the check_scope() function should echo the same results as the explicit checks inside the constructors. Previous Comments: ------------------------------------------------------------------------ [2014-02-08 00:31:50] requinix@php.net It's a matter of inheritance, not accessibility: the subclasses do not inherit the private properties of the superclasses. The properties really don't exist. ------------------------------------------------------------------------ [2014-02-08 00:15:14] mpope at homeimprovementleads dot com Description: ------------ Despite reporting as fixed ( https://bugs.php.net/bug.php?id=50810 ) and closed in 5.3.3 according to the change log, a small variation in the logic still produces a bug in 5.5.9. The fix in 50810 only worked because the method checking the private property was in the same class as the private property. If you attempt to check the private property of a superclass from the subclass it reports false. Although I would normally expect this behavior, I think it is counter to the statement found in the docs for property_exists in the change log section: "5.3.0 This function checks the existence of a property independent of accessibility." Test script: --------------- <?php function check_scope($ref) { echo "vs\n"; var_dump(property_exists($ref, 'foo')); var_dump(property_exists($ref, 'goo')); var_dump(property_exists($ref, 'poo')); echo "\n"; } class a { private $foo; public function __construct() { var_dump(property_exists($this, 'foo')); var_dump(property_exists($this, 'goo')); var_dump(property_exists($this, 'poo')); check_scope($this); } } class b extends a { private $goo; public function __construct() { var_dump(property_exists($this, 'foo')); var_dump(property_exists($this, 'goo')); var_dump(property_exists($this, 'poo')); check_scope($this); parent::__construct(); } } class c extends b { private $poo; public function __construct() { var_dump(property_exists($this, 'foo')); var_dump(property_exists($this, 'goo')); var_dump(property_exists($this, 'poo')); check_scope($this); parent::__construct(); } } new c(); Expected result: ---------------- Given the accessibility consideration I would expect property_exists to return true in all of the cases outlined in the test script. However, running the script will show that property existence checks depend on both the location of the private variable definition AND the location of the property_exists method call. The results in the check_scope() method do not match the results of the same logic copy and pasted into each constructor method. Actual result: -------------- bool(false) bool(false) bool(true) vs bool(false) bool(false) bool(true) bool(false) bool(true) bool(true) vs bool(false) bool(false) bool(true) bool(true) bool(false) bool(true) vs bool(false) bool(false) bool(true) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=66670&edit=1

« previous php.bugs (#184246) next »