|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-06-11 10:28 UTC] degeberg@php.net
-Status: Open
+Status: Bogus
[2010-06-11 10:28 UTC] degeberg@php.net
[2010-06-11 11:12 UTC] public at proside dot fr
[2010-06-11 11:52 UTC] degeberg@php.net
[2010-06-11 12:12 UTC] public at proside dot fr
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 11:00:01 2025 UTC |
Description: ------------ In one case, the PHP engine allows access to the protected methods of an instanciated class As the documentation says : protected methods are only available inside the class that declares it and inside the tree of derivated classes. If you look at the code, we are in none of these case : $a is a standalone instance of MyParent so the protected methods of class MyParent should be hidden. Am i wrong ? Test script: --------------- <?php class MyParent { protected function getProtectedParent() { return 'Parent_Protected'; } } class MyChild extends MyParent { function getPublicChild() { # --> new standalone instance of MyParent $a = new MyParent(); # --> here it's possible to access to the protected method of $a ! return $a->getProtectedParent(); } } $cls = new MyChild(); $test = $cls->getPublicChild(); Expected result: ---------------- Fatal error : access level violation Actual result: -------------- $test = 'Parent_Protected'