php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62690 Sibling property with same name accessible in sibling is detected as accessible
Submitted: 2012-07-29 17:28 UTC Modified: 2017-10-24 08:23 UTC
From: cataphract@php.net Assigned: requinix (profile)
Status: Closed Package: Reflection related
PHP Version: master-Git-2012-07-29 (Git) OS: Irrelevant
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: cataphract@php.net
New email:
PHP Version: OS:

 

 [2012-07-29 17:28 UTC] cataphract@php.net
Description:
------------
See script.

Test script:
---------------
<?php
class Foo {}
        
class Bar extends Foo { 
        public $var = 'BarVar';
}

class Qux extends Foo {
        private $var = 'QuxVar';
}

$class = new ReflectionClass('Bar');
$prop = $class->getProperty('var');
echo $prop->getValue(new Qux());

Expected result:
----------------
A 'ReflectionException' with message 'Given object is not an instance of the class this property was declared in'.

This would mirror the behavior with methods:

<?php
class Foo {}
        
class Bar extends Foo {
	function foo() {}
}

class Qux extends Foo {
	private function foo() {}
}

$class = new ReflectionClass('Bar');

$meth = $class->getMethod('foo');
$meth->invoke(new Qux());

PHP Fatal error:  Uncaught exception 'ReflectionException' with message 'Given object is not an instance of the class this method was declared in'

Actual result:
--------------
PHP Fatal error:  Cannot access private property Qux::$var

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-29 17:28 UTC] cataphract@php.net
-Assigned To: +Assigned To: cataphract
 [2017-10-24 07:59 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: cataphract +Assigned To:
 [2017-10-24 08:23 UTC] requinix@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: requinix
 [2017-10-24 08:23 UTC] requinix@php.net
Fixed since 7.1. https://3v4l.org/Y9ShB
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 18:01:34 2025 UTC