#34237 [Opn->Bgs]: A protected method should cause a fatal error if called publicly.
| From: | helly@php.net | Date: | Wed, 24 Aug 2005 18:58:11 +0000 |
| Subject: | #34237 [Opn->Bgs]: A protected method should cause a fatal error if called publicly. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-83954@lists.php.net to get a copy of this message | ||
ID: 34237
Updated by: helly@php.net
Reported By: barry dot verdon at complinet dot com
-Status: Open
+Status: Bogus
Bug Type: Class/Object related
-Operating System: Redhat el3
+Operating System: *
-PHP Version: 5.0.4
+PHP Version: 5.*
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
In that scope you're allowed to call protected member functions. Since
it is a compatible scope. In other words visibility works scope/class
wise not object wise.
Previous Comments:
------------------------------------------------------------------------
[2005-08-24 18:41:56] barry dot verdon at complinet dot com
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 this bug report at http://bugs.php.net/?id=34237&edit=1