note 17289 added to keyword.parent

From: Date: Mon, 03 Dec 2001 14:49:55 +0000
Subject: note 17289 added to keyword.parent
Groups: php.notes 
Request: Send a blank email to php-notes+get-21562@lists.php.net to get a copy of this message
For al@humantouch.de : actually there is a way : class test { function test1(){ echo "parent:test1";} function test2(){ echo "parent:test2"; test::test1(); // do not use $this here } } class sub extends test { function test1(){ echo "sub:test1";} function test2(){ echo "sub:test2"; parent::test2(); } } $a = new sub(); $a->test2(); /* returns: sub:test2 parent:test2 parent:test1 */ However itsbruce@netscape.net is right to point out that the default behavior is what you most probably expect : Think about class SortAlgorithms{ function max($a,$b){ /* default to integer comparison in base class*/ } function firstAlgorithm($myarray){ /* some loop */ $max = $this->max($a, $b); //etc ... } } Class SortStrings extends SortAlgorithms{ function max($a, $b){ /*some string comparison*/ } // that's all } Now when you execute any algorithm, which compare function do you expect in the SortStrings class ? Ivan -- http://www.php.net/manual/en/keyword.parent.php http://master.php.net/manage/user-notes.php?action=edit+17289 http://master.php.net/manage/user-notes.php?action=delete+17289 http://master.php.net/manage/user-notes.php?action=reject+17289

« previous php.notes (#21562) next »