|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[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
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 14:00:01 2025 UTC |
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