如何在类实例化中传递数组作为构造函数参数?传递数组作为类构造函数的参数
abstract class Person {
protected function __construct(){
}
public static final function __callStatic($name, $arguments){
return new $name($arguments);
}
}
class Mike extends Person {
protected function __construct($age, $hobby){
echo get_called_class().' is '.$age.' years old and likes '.$hobby;
}
}
// =============================================
Person::Mike(15, 'golf');
这应该输出
迈克15岁,喜欢打高尔夫球
但我得到的第二个参数Mike
的构造缺少的,因为从__callStatic
这两个参数都为发数组到$age
。我的问题是我怎样才能发送他们作为参数,而不是数组?
这已经有一段时间,因为我用PHP的工作,但你不应该在构造函数,而不是1使用2x_? – Jonast92 2014-09-12 15:48:21
@ Jonast92我的错误。 Thx指出它 – 2014-09-12 15:50:12