Any possibility to get hold of parent calling child object?
<p>following piece of code:</p>

<pre><code> class a{

        public function __get($key) {
            if($key == 'obj') {
                if($b-&gt;obj == null) { //PSEUDO this is what I intend to do :)
                   $obj = new Obj();                        
                   $b-&gt;obj = $obj
                }
                return $obj;
            }
        }
    }

 class b extends a{

        private $obj = null;


        public function __get($key) {
            return parent::__get($key);
        }

    }
</code></pre>

<p>So the idea is to create objects on demand. But I don't know if it's possible to detect the class of the object that is calling the parent::_get method. Some operator like child is what I am looking for I guess :).</p>

<p>What is possible but redundant is that for example I have one object called Country, so I define in my class User which has a Country object and another class Location with also has a Country object. Both classes extend class a. I could solve the problem by writing the if block from class a into each of the child classes. But that is what I do not want to do. So it would be easier to be able to check in class a which class called the __get function and to set the desired Country object directly into the child class. I hope my problem becomes clear and it's not too weird hehe. Though I am open for any other solutions... Thanks.</p>
