我有一个抽象类,其中包含这样的 __construct 方法
abstract class Model
{
protected $attributes = [];
public function __construct(array $attributes = []) {
$this->$attributes = $attributes;
}
}
然后在我的具体类中我扩展了抽象模型
class Pong extends Model
{
}
当我转储构造函数内的属性时,我得到一个空数组,但如果删除构造函数参数的默认值,Pong 模型就有属性。挑战是,我希望能够使用默认值和不使用默认值来构造具体类
$pong = new Pong();
$pong = new Pong(['msg' => 'Hello Kitty']);
牛魔王的故事