|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-09-30 01:23 UTC] atblock at gmail dot com
Description:
------------
I have a class which inherits from another class. The base class has a
private property. When I check if that property exists on the inherited
class, it returns true.
Reproduce code:
---------------
class A {
private $a;
}
class B extends A {
}
$a = new B;
$ref = new ReflectionClass($a);
var_dump($ref->hasProperty('a'));
Expected result:
----------------
bool(false)
Actual result:
--------------
bool(true)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 00:00:01 2025 UTC |
1) Because it's a member of the base class and it's private. 2) Because the equivalent $ref->getProperty('a') throws an error, of unknown propertyYou are right. It can be expected that if hasProperty('a') returns true, getProperty('a') works. This works correctly when reflecting on A, but not when reflecting on B. Actual: Reflect on: A B hasProperty: y y getProperty: y n I am not sure what the expected behavior should be. I.e. whether hasProperty should return true or false on B.