Я ищу способ автоматического вызова конструктора родительского класса (?) Из дочернего класса:
(Примечание: это только пример, поэтому могут быть ошибки при наборе)
Class myParent()
{
protected $html;
function __construct( $args )
{
$this->html = $this->set_html( $args );
}
protected function set_html( $args )
{
if ( $args['foo'] === 'bar' )
$args['foo'] = 'foobar';
return $args;
}
}
Class myChild extends myParent
{
public function do_stuff( $args )
{
return $this->html;
}
}
Class myInit
{
public function __construct( $args )
{
$this->get_stuff( $args );
}
public function get_stuff( $args )
{
$my_child = new myChild();
print_r( $my_child->do_stuff( $args ) );
}
}
$args = array( 'foo' => 'bar, 'what' => 'ever' );
new myInit( $args );
// Should Output:
/* Array( 'foo' => 'foobar', 'what' => 'ever' ) */
Чего я хочу избежать, так это вызова (внутри класса myChild) __construct( $args ) { parent::__construct( $args ); }
.
Вопрос: возможно ли это? Если так: как?
Спасибо!