Does static method in PHP have any difference with non-static method?

前端 未结 6 867
我寻月下人不归
我寻月下人不归 2020-12-03 08:21
class t {
    public function tt()
    {
        echo 1;
    }
}
t::tt();

See?The non-static function can also be called at class level.So what\'s

6条回答
  •  一生所求
    2020-12-03 08:58

    A main difference that has not been mentioned relates to polymorphic behavior.

    Non static methods, when redeclared in a derived class, override the base class method, and allow polymorphic behavior based on the type of the instance they are called on. This is not the case for static methods.


    PHP 5.3 introduced the concept of late static binding which can be used to reference the called class in a context of static inheritance.

提交回复
热议问题