【发布时间】:2012-03-09 19:19:09
【问题描述】:
我将创建一个(某种)工厂类,它接受可变数量的参数并将它们传递给它将调用的类
<?php
class A {
private $a;
private $b;
private $c;
public function __construct($a=1, $b=2, $c=3){
$this->a = $a;
$this->b = $b;
$this->c = $c;
}
}
class B {
private $foo;
public function __construct(){
$args = func_get_args();
$this->foo = call_user_func_array(array('A', '__construct'), $args);
}
public function getObject(){
return $this->foo;
}
}
$b = new B(10, 20, 30);
var_dump($b->getObject()); // should return equivalent of new A(10,20,30);
我收到了这个错误
PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, non-static method A::__construct() cannot be called statically
【问题讨论】: