Bug #66670 [NEW]: property_exist cannot find private properties defined in superclass
| From: | mpope at homeimprovementleads dot com | Date: | Sat, 08 Feb 2014 00:15:15 +0000 |
| Subject: | Bug #66670 [NEW]: property_exist cannot find private properties defined in superclass | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-184200@lists.php.net to get a copy of this message | ||
From: mpope at homeimprovementleads dot com
Operating system: windows 7
PHP version: 5.5.9
Package: Class/Object related
Bug Type: Bug
Bug description:property_exist cannot find private properties defined in superclass
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 bug report at https://bugs.php.net/bug.php?id=66670&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66670&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66670&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66670&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66670&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66670&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66670&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66670&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66670&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66670&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66670&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66670&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66670&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66670&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66670&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66670&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66670&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66670&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66670&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66670&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66670&r=mysqlcfg