php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49719 ReflectionClass::hasProperty returns true for a private property in base class
Submitted: 2009-09-30 01:23 UTC Modified: 2009-11-01 15:12 UTC
From: atblock at gmail dot com Assigned: felipe (profile)
Status: Closed Package: Reflection related
PHP Version: 5.3SVN-2009-09-30 (snap) OS: Linux
Private report: No CVE-ID: None
 [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)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-10-01 11:20 UTC] sjoerd@php.net
From the documentation of hasMethod(), it seems that private properties also count as properties. Why do you think this is a bug? Because the property is not defined in class B but in class A?
 [2009-10-01 12:22 UTC] atblock at gmail dot com
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 property
 [2009-10-04 19:49 UTC] Sjoerd@php.net
You 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.
 [2009-11-01 15:12 UTC] svn@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&revision=290127
Log: - Fixed bug #49719 (ReflectionClass::hasProperty returns true for a private property in base class)
 [2009-11-01 15:12 UTC] felipe@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 09:01:32 2024 UTC