PHP inheriting/extending a particular instance of an Object
        Posted  
        
            by 
                delta9
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by delta9
        
        
        
        Published on 2012-09-24T21:35:59Z
        Indexed on 
            2012/09/24
            21:37 UTC
        
        
        Read the original article
        Hit count: 233
        
Is there any way to force PHP to extend an existing/particular (and for that matter, already instantiated) instance of an object?
This imaginary code should explain what I am wondering:
class Base
{
     public $var;
     function __construct($var){
         $this->var = $name;
     }
}
class Extender extends Base { 
    function __construct($parent)
    {
         parent = $parent;  
    }
}
$base = new Base('yay!');
$extender = new Extender($base);
echo 'Extended base var value: '.$extender->var.'<br/>';
Output (would be):
Extended base var value: yay!
To be clear, I am wanting to instantiate an object that extends a PARTICULAR INSTANCE of another object, one that has already been instantiated.
I am aware that I can pass a reference to an object to another object (via it's constructor function) and then add it as a property of the receiving object, I'm wondering if there is a real way to do this?
© Stack Overflow or respective owner