Re: Extending a Class

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* Jason Barnett <jason.barnett@xxxxxxxxxxxxx>:
> Matthew Weier O'Phinney wrote:
> > * Phillip S. Baker <phillipsbaker@xxxxxxxxx>:
> ...
> > The object *instance* only gets to access the overridden method (assuming
> > it's an instance of the child class):
> > 
> >     $instance->someMethod();
> > 
>
> This is 100% correct, but just to clarify: it is possible to do 
> something like this:
>
> class myParent
> {
>    function someMethod()
>    {
>      return "I am myParent.\n";
>    }
> }
>
> class myChild extends myParent
> {
>    function someMethod()
>    {
>      echo parent::someMethod();
>      echo "I am myChild\n";
>    }
> }
>
> $instance = new myChild();
> $instance->someMethod();

Which... if you'd read further in my post, I mentioned -- you typically
do this -- s you did in your example --  when in an overridden method
and need access to the parent class' version of the method.

-- 
Matthew Weier O'Phinney           | mailto:matthew@xxxxxxxxxx
Webmaster and IT Specialist       | http://www.garden.org
National Gardening Association    | http://www.kidsgardening.com
802-863-5251 x156                 | http://nationalgardenmonth.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux