Re: [PHP4BETA] Child function never get called

From: Date: Mon, 26 Jul 1999 15:42:16 +0000
Subject: Re: [PHP4BETA] Child function never get called
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-2768@lists.php.net to get a copy of this message
So there's no way to override a parent's function? Here's an example of what i want to do: <?PHP class parentclass { function foo($bar) { $bar++; return($bar); } }; class childclass extends parentclass { function foo($bar) { $bar=parentclass::foo($bar); $bar++; return($bar); } }; $obj=new childclass(); $bar=$obj->foo(0); //This calls the parent's function echo $bar; ?> I want this to echo 2 (which would mean both the parent and child function gets called), but it echoes 1 because only the parent function gets called! The problem with calling the child's function from the parent function is that i have more then one class that extends the parent and it woule not be elegant or effective to keep track of child classes from the parent class... Is there any way around this? Thanks, Johan Isacsson On Mon, 26 Jul 1999, Andi Gutmans wrote: > At 11:06 AM 7/26/99 +0200, Johan Isacsson wrote: > >Hi. > > > >I have a problem with an overriding child function. The parent function > >gets called instead of the child function. I've tried to chane name of the > >child function to something that no function in the parent object has and > >it works then. Any ideas? > > If you override the child function only the parent function will be called. > You can explictly call the child function from your parent function with > the classname::function_name() function call syntax. > > Andi > --- > Andi Gutmans <andi@zend.com> > http://www.zend.com/ > > -- > PHP 4 Beta > >

« previous php.version4 (#2768) next »