Late Static Binding Example

Example

class A
{
    static public $data = 'A';
    
    static public function set()
    {
        //self::$data = '--'; //normal binding
        static::$data = '--'; //late binding
    }
}

class B extends A
{
    static public $data = 'B';
}

class C extends A
{
    static public $data = 'C';
}


echo A::$data, B::$data, C::$data;
C::set();
echo A::$data, B::$data, C::$data;

normal binding

ABC--BC

late binding

ABCAB--
CategoriesUncategorizedTags

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.