Get parent object from object
2 answers
You can not.
object1
is not a parent, it is a container. If you want to access a function object1
from object2
, you must have a link to object1
.
Use this type of template:
class class1
{
public $child;
public function __construct()
{
$this->child = new class2($this);
}
}
class class2
{
private $parent;
public function __construct(class1 $parent)
{
$this->parent = $parent;
}
}
Is this what you are looking for?
+4
source to share