Search This Blog

Thursday, January 12, 2012

Difference of self and static in inheritance, php example


class A {
    public static function get_A() {
        return new self();
    }
    public static function get_me() {
        return new static();
    }
}

class B extends A {

}

echo get_class(B::get_A());  // out put A
echo get_class(B::get_me()); // out put B
echo get_class(A::get_me()); // out put A

No comments: