note 101548 added to keyword.extends

From: Date: Thu, 23 Dec 2010 19:32:29 +0000
Subject: note 101548 added to keyword.extends
Groups: php.notes 
Request: Send a blank email to php-notes+get-175178@lists.php.net to get a copy of this message
If you have a class that extends an other and both classes have a function with the same name then visibility to both classes should be the same, else you will have a fatal error. An other interested part in the example bellow is that if visibility of the showName method is private then $this->name() will execute the showName method on class test. If it is public or protected it will execute method showName on class extendTest. class test { public function __construct() { } public function name() { $this->xname('John'); } private function showName($name) { echo 'my name in test is '.$name; } } class extendTest extends test { public function __construct() { parent::__construct(); } private function showName($name) { echo 'my name in extendTest is '.$name; } } $test = new extendTest(); $test->name(); result: my name in test is John If we change visibility of the showName method to public or protected then the result of the above will be: my name in extendTest is John ---- Server IP: 69.147.83.197 Probable Submitter: 88.218.138.11 ---- Manual Page -- http://www.php.net/manual/en/keyword.extends.php Edit -- https://master.php.net/note/edit/101548 Del: integrated -- https://master.php.net/note/delete/101548/integrated Del: useless -- https://master.php.net/note/delete/101548/useless Del: bad code -- https://master.php.net/note/delete/101548/bad+code Del: spam -- https://master.php.net/note/delete/101548/spam Del: non-english -- https://master.php.net/note/delete/101548/non-english Del: in docs -- https://master.php.net/note/delete/101548/in+docs Del: other reasons-- https://master.php.net/note/delete/101548 Reject -- https://master.php.net/note/reject/101548 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#175178) next »