In PHP OOP, it is possible to call an object's parent method, by externally referencing that object?
Class ObjectOne {
protected function method() {
// Does something simple
}
}
Class ObjectTwo extends ObjectOne {
protected function method() {
$temp = clone $this;
$this->change_stuff();
if(parent::method()) {
// Do more stuff here
$temp->method();
// This will call this method, not the parent's method.
}
}
protected function change_stuff() {
// Change this object's stuff
}
}
I can't call parent::method() because this will cause the current object to execute it's method. I want the $temp ones's instead.
SOLVED
I solved it by writing another function that calls the parent::update()
method from inside the class:
Class ObjectOne {
protected function method() {
// Does something simple
}
}
Class ObjectTwo extends ObjectOne {
protected function method() {
$temp = clone $this;
$this->change_stuff();
if(parent::method()) {
// Do more stuff here
$temp->update_parent();
// This will call this method, not the parent's method.
}
}
protected function change_stuff() {
// Change this object's stuff
}
protected function update_parent() {
return parent::update();
}
}