Php Laravel late静态绑定为static::其中
好的,我读了一些关于PHP后期静态绑定的方法和变量的理解。但从中的第28行开始,它使用withPhp Laravel late静态绑定为static::其中,php,laravel,late-static-binding,Php,Laravel,Late Static Binding,好的,我读了一些关于PHP后期静态绑定的方法和变量的理解。但从中的第28行开始,它使用with,其中,这是一种Laravel收集方法。我不明白这里发生了什么,static::where()。集合的位置,以便您可以使用Where() 例如: 所以static::where()指的是Tag::where()。这同样适用于static::create()这是在扩展illighted\Database\Eloquent\model中使用模型中的wherIn(),而不是集合中的Tag类。谢谢。很高兴知道。
,其中
,这是一种Laravel收集方法。我不明白这里发生了什么,static::where()
。集合的位置,以便您可以使用Where()
例如:
所以
static::where()
指的是Tag::where()
。这同样适用于static::create()
这是在扩展illighted\Database\Eloquent\model中使用模型中的wherIn(),而不是集合中的Tag类代码>。谢谢。很高兴知道。另一个有用的。谢谢。但你的例子是关于变量的。但Tag是一个模型。那么它是如何关联的呢?在laravel的范围内,Tag
是一个模型。在OOP的范围内,Tag
是一个对象。在编程范围内,标记是语言中的一个专用空间,表示一些概念或包含一个值。变量也是如此。
/**
* Add any tags needed from the list
*
* @param array $tags List of tags to check/add
*/
public static function addNeededTags(array $tags)
{
if (count($tags) === 0) {
return;
}
$found = static::whereIn('tag', $tags)->lists('tag')->all();
foreach (array_diff($tags, $found) as $tag) {
static::create([
'tag' => $tag,
'title' => $tag,
'subtitle' => 'Subtitle for '.$tag,
'page_image' => '',
'meta_description' => '',
'reverse_direction' => false,
]);
}
}
class a
{
static protected $test = "class a";
public function static_test()
{
echo static::$test; // Results class b
echo self::$test; // Results class a
}
}
class b extends a
{
static protected $test = "class b";
}
$obj = new b();
$obj->static_test();