|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-08-24 20:58 UTC] helly@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 21:00:01 2025 UTC |
Description: ------------ A protected function is accessible publicly if a child class has a public function that instantiates the child object and calls the protected function. This public function can then be called publicly. I would have expected a fatal error to be produced from the protected function call. Is this intended behaviour? Or should I declare the function as public in the case of this not being the desired functionality and may change at a later point? Reproduce code: --------------- <?php class parentClass { protected function protectedFunction() { print("This is a protected function."); } } class childClass extends parentClass { public function publicFunction() { $childClass = new childClass(); $childClass->protectedFunction(); } } $childClass = new childClass(); $childClass->publicFunction(); ?> Expected result: ---------------- Fatal Error on line 11, $childClass->protectedFunction(). Actual result: -------------- This is a protected function.