#34237 [NEW]: A protected method should cause a fatal error if called publicly.

From: Date: Wed, 24 Aug 2005 16:41:58 +0000
Subject: #34237 [NEW]: A protected method should cause a fatal error if called publicly.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-83951@lists.php.net to get a copy of this message
From: barry dot verdon at complinet dot com Operating system: Redhat el3 PHP version: 5.0.4 PHP Bug Type: Class/Object related Bug description: A protected method should cause a fatal error if called publicly. 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. -- Edit bug report at http://bugs.php.net/?id=34237&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=34237&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=34237&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=34237&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=34237&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=34237&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=34237&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=34237&r=needscript Try newer version: http://bugs.php.net/fix.php?id=34237&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=34237&r=support Expected behavior: http://bugs.php.net/fix.php?id=34237&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=34237&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=34237&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=34237&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=34237&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=34237&r=dst IIS Stability: http://bugs.php.net/fix.php?id=34237&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=34237&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=34237&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=34237&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=34237&r=mysqlcfg

« previous php.bugs (#83951) next »