我理解是:
调用 Model::where()
,Model
里没有静态方法 where()
,于是会触发 __callStatic()
,
在 __callStatic()
中会试图去调用实例方法 where()
,Model
也没有 where()
,于是触发 __call()
,
在 __call()
中实例化 \Illuminate\Database\Eloquent\Builder
,然后调用 Builder
的实例方法 where()
。
调用 Model::getTable()
Model
里没有静态方法 getTable()
,于是会触发 __callStatic()
,
在 __callStatic()
中会试图去调用实例方法 getTable()
,Model
有定义,所以应该直接调用getTable()
。
但是却报错
Non-static method Illuminate\Database\Eloquent\Model::getTable() should not be called statically, assuming $this from incompatible context
查了一下错误的原因,鸟哥在这篇文章解释了,PHP 的 Calling Scope
问题是,那为什么可以用 Model::where()
?
qq_笑_17
慕标琳琳
噜噜哒