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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 20:01:45 2024 UTC