2009-11-12 2 views

ответ

1

Вы можете установить производный класс, чтобы взять объект BaseClass в качестве параметра в конструкторе, а затем скопировать свойства от:

class Base { 
    var $x, $y; 
} 

class DerivedClass extends Base { 
    function __construct($param) { 
     $this->copyFromBase($param); // put some type-checking here... 
    } 

    function copyFromBase($base) { 
     $this->x = $base->x; // you could definitely use a more 
     $this->y = $base->y; // intelligent way to do this 
    } 
} 

$b = new Base(); 
$b->x = 'X'; 
$b->y = 'Y'; 
$b = new Derived($b);