How To Pass A Reference To An Existing Object From One Class To Another In PHP
erics, February 2nd, 2012
Inside class “yourClassA” calling “yourClassB”:
1 2 3 4 |
class yourClassA { $classObject = new yourClassB; $classObject->setClass($this); } |
Inside class “yourClassB” getting the call from “yourClassA”:
1 2 3 4 5 6 7 8 9 10 |
class yourClassB { public function setClass($object = NULL) { if(is_object($object) and $object instanceof yourClassA) { $this->RefToClassA = $object; $this->yourVar = $RefToClassA->otherVar; // etc, etc, etc... } } } |