Page 1 of 1
OOP - $parent?
Posted: Tue Aug 08, 2006 5:22 am
by MarK (CZ)
Is there any way to access the parent instance of an object?
E.g. in method $object->subobject->Method() I want to access $object->var. Is it possible with something like $parent? I know it doesn't exist but is there similar way to do so?
Posted: Tue Aug 08, 2006 5:25 am
by volka
$object->subobject->Method() doesn't make object the parent of $subobject.
You can pass $object-var as parameter of the method call.
Posted: Tue Aug 08, 2006 5:27 am
by MarK (CZ)
I've maybe used a bad word, not parent like in the way of extending the class but it is just higher in the hierarchy..
Posted: Tue Aug 08, 2006 8:52 am
by feyd
debug_backtrace() can tell you what class, and possibly a reference to the containing object from within the enclosed class' method.. but it should probably be given to the enclosed class in some fashion.. Although this is bad OOP behavior.
Posted: Tue Aug 08, 2006 10:39 am
by Christopher
Code: Select all
class Object {
var $children = array();
var $parent = null;
function newChild() {
$child = new Object();
$child->parent = $this;
$this->children[] = $child;
return $child;
}
function getParent() {
return $thils->parent;
}
}