$this->attributes ['email'] 是什么用法?
$this->attributes['email'] 是PHP自己的语法吗?
为什么不直接用 $this->email
求教,谢谢!
当使用
$user->email
时, 因为User.php
和它所继承的类(父类或者 trait) 中都没有email
这个属性,这时候会调用Model
类 的__get()
这个魔术方法。我们继续追踪
通过注释我们知道,他调用了
Model
类的attributes
属性, 这个属性是通过这个 trait 引入的。