实例化对象而不在 PHP 中调用其构造函数
2022-08-30 21:02:13
另一种方法是创建该类的子类,其中包含和空构造函数
class Parent {
protected $property;
public function __construct($arg) {
$this->property = $arg;
}
}
class Child extends Parent {
public function __construct() {
//no parent::__construct($arg) call here
}
}
,然后使用子类型:
$child = new Child();
//set properties with reflection for child and use it as a Parent type