All pastes #982723 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-04-12 20:28 UTC
rendered paste body
<?php
class A
{
    private $a;
    protected $b;
    public $c;

    function __construct($a, $b, $c)
    {
        $this->a = $a;
        $this->b = $b;
        $this->c = $c;
    }
    
    protected function getVariables()
    {
        return get_object_vars($this);
    }
    
    protected function setVariable($var,$value)
    {
        $this->$var = $value;
    }
}

class B extends A
{    
    public function __construct(A $objA)
    {
        foreach($objA->getVariables() as $key => $value)
            {
                $this->setVariable($key, $value);
            }
        
    }
    
    
}


$obj= new A('pierwsza', 'druga', 'trzecia');
$obj = new B($obj);

var_dump($obj); // ["a:private"]=>"pierwsza" ["b:protected"]=>"druga" ["c"]=>"trzecia"
?>