note 92204 added to language.oop5.basic
| From: | the_french_cow at hotmail dot com | Date: | Tue, 14 Jul 2009 13:54:54 +0000 |
| Subject: | note 92204 added to language.oop5.basic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158271@lists.php.net to get a copy of this message | ||
For those of us who are new to inheritance, private functions are not visible in an inherited class.
Consider:
<?php
class A {
protected function func1() {
echo("I'm func1 in A!<br/>");
}
private function func2() {
echo("I'm func2 in A!<br/>");
}
}
class B extends A {
public function func3() {
echo("I'm func3 in B!<br/>");
$this->func1();
$this->func2(); // Call to private function from extended class results in a fatal error
}
}
$b = new B;
$b->func3(); // Ends in a fatal error
// OR
$b->func1(); // Call to protected function from outside world results in a fatal error
?>
If you want a function to be accessible in class B but not to the outside world, it must be declared
as protected.
----
Server IP: 209.41.74.194
Probable Submitter: 66.78.98.194
----
Manual Page -- http://www.php.net/manual/en/language.oop5.basic.php
Edit -- https://master.php.net/note/edit/92204
Del: integrated -- https://master.php.net/note/delete/92204/integrated
Del: useless -- https://master.php.net/note/delete/92204/useless
Del: bad code -- https://master.php.net/note/delete/92204/bad+code
Del: spam -- https://master.php.net/note/delete/92204/spam
Del: non-english -- https://master.php.net/note/delete/92204/non-english
Del: in docs -- https://master.php.net/note/delete/92204/in+docs
Del: other reasons-- https://master.php.net/note/delete/92204
Reject -- https://master.php.net/note/reject/92204
Search -- https://master.php.net/manage/user-notes.php