update page now
Laravel Live Japan

Voting

: one plus eight?
(Example: nine)

The Note You're Voting On

israfilov93 at gmal dot com
7 years ago
one of academic example, when forward_static_call() can be useful

<?php

class A
{
    public static function test()
    {
        var_dump('we were here');
        return static::class;
    }
}

class B extends A
{
    public static function test()
    {
        return self::class;
    }
}

class C extends B
{
    public static function test()
    {
        $grandParent = get_parent_class(parent::class); // $grandParent is A
        return forward_static_call([$grandParent, __FUNCTION__]); // calls A::test()
    }
}

// prints 
// string(12) "we were here"
// string(1) "C"
var_dump(C::test());

<< Back to user notes page

To Top