Re: [PHP4BETA] Child function never get called
| From: | Johan Isacsson | Date: | Mon, 26 Jul 1999 22:58:19 +0000 |
| Subject: | Re: [PHP4BETA] Child function never get called | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-2818@lists.php.net to get a copy of this message | ||
This is strange, the example i gave you actually echoes 2...
But in the real program which is a bit more complex, it dont work, the
child function dont get called. I saw some cvs info about iheritance with
included files, all my classes are separate includes, could that have
something to do with it? In that case, is it possible to get it? I would
really need it :)
Thanks, Johan Isacsson
On Mon, 26 Jul 1999, Andi Gutmans wrote:
> I'll take a look at it. From the first glance this should echo 2.
>
> Andi
>
> At 05:42 PM 7/26/99 +0200, Johan Isacsson wrote:
> >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
> > >
> > >
>
> ---
> Andi Gutmans <andi@zend.com>
> http://www.zend.com/
>
> --
> PHP 4 Beta
>
>