note 68396 added to language.oop5.abstract

From: Date: Tue, 25 Jul 2006 15:27:20 +0000
Subject: note 68396 added to language.oop5.abstract
Groups: php.notes 
Request: Send a blank email to php-notes+get-115161@lists.php.net to get a copy of this message
It took me a while to figure this out and i couldn't find it easily in the documentation anywhere. If you want to override a method from a base class and want to call the base class in the method, then you have to use the parent::function() syntax, even though the method isn't static. There is no $base variable in php that i know of. Expamle: <?php public abstract class BasePerson() { /* * alot of code.. */ public function getName() { return $this->name; } } public class Person() extends BasePerson { /* * alot of code.. */ // override of base getName().. public function getName() { // you would expect $base->getName() instead of parrent::getName()... return htmlspecialchars(parent::getName()); } } ?> Hope this helps! ---- Server IP: 66.163.161.117 Probable Submitter: 193.172.248.34 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.abstract.php Edit -- http://master.php.net/note/edit/68396 Del: integrated -- http://master.php.net/note/delete/68396/integrated Del: useless -- http://master.php.net/note/delete/68396/useless Del: bad code -- http://master.php.net/note/delete/68396/bad+code Del: spam -- http://master.php.net/note/delete/68396/spam Del: non-english -- http://master.php.net/note/delete/68396/non-english Del: in docs -- http://master.php.net/note/delete/68396/in+docs Del: other reasons-- http://master.php.net/note/delete/68396 Reject -- http://master.php.net/note/reject/68396 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#115161) next »