By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,677 Members | 1,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,677 IT Pros & Developers. It's quick & easy.

access parent method php4

P: n/a
RR
I have two classes:

class Base
{
function Insert()
{
// does stuff
}
}

class Derived extends Base
{
function Insert()
{
// does some different stuff
parent::Insert(); // then calls base class
}
}

Now, in main line code I want to do this:

$der = new Derived();

$der->parent::Insert(); // I want to call the base class's Insert
method - doesn't work

$der->Base::Insert(); // this doesn't work either

Is it possible to access a hidden parent class method with a child class
object in PHP4?

thanks,
RR
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
With total disregard for any kind of safety measures "RR"
<ne****************@spamgourmet.com> leapt forth and uttered:
I have two classes:

class Base
{
function Insert()
{
// does stuff
}
}

class Derived extends Base
{
function Insert()
{
// does some different stuff
parent::Insert(); // then calls base class
}
}

Now, in main line code I want to do this:

$der = new Derived();

$der->parent::Insert(); // I want to call the base
class's Insert method - doesn't work

$der->Base::Insert(); // this doesn't work either

Is it possible to access a hidden parent class method with a
child class object in PHP4?

thanks,
RR


When you extend a class you override any methods from the parent
class that have the same name. But if you just call $der->insert()
then it should work as long as Derived::insert() includes the call
to it's parent method.

--
Phil Roberts | Dork Pretending To Be Hard | http://www.flatnet.net/
Jul 17 '05 #2

P: n/a
RR,

I guess you need to write an aditional method:

class Derived extends Base
{
function Insert()
{
// does some different stuff
parent::Insert(); // then calls method from base class
}

functon baseInsert()
{
parent::Insert();
}
}
then call $der->basInsert();

Alternativily you could rename the Direved::Insert() method:
class Derived extends Base
{
function extendedInsert()
{
// does some different stuff
$this->Insert(); // then calls inherited method
}
}

These two solutions will give different polymorphisms for Insert(). I
mean, if you can have arrays like:

$polymorhicArray = array( new Base(), new Derived(), new Base() );

and you would want to do:

forEach ($polymorhicArray as $baseOrDerived)
$baseOrDerived->Insert();

Then i guess only one of the above solutions will do what you want.

Greetings,

Henk Verhoeven,
www.phpPeanuts.org.

RR wrote:
I have two classes:

class Base
{
function Insert()
{
// does stuff
}
}

class Derived extends Base
{
function Insert()
{
// does some different stuff
parent::Insert(); // then calls base class
}
}

Now, in main line code I want to do this:

$der = new Derived();

$der->parent::Insert(); // I want to call the base class's Insert
method - doesn't work

$der->Base::Insert(); // this doesn't work either

Is it possible to access a hidden parent class method with a child class
object in PHP4?

thanks,
RR


Jul 17 '05 #3

P: n/a
RR

"Henk Verhoeven" <ne**@metaclassREMOVE-THIS.nl> wrote in message
news:c3**********@news3.tilbu1.nb.home.nl...
I guess you need to write an aditional method:

class Derived extends Base
{
function Insert()
{
// does some different stuff
parent::Insert(); // then calls method from base class
}

functon baseInsert()
{
parent::Insert();
}
}
then call $der->basInsert();


Thanks. That's what I did....just hoping for a better (more direct)
solution.

RR
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.