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

前端 未结 6 866
我寻月下人不归
我寻月下人不归 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:34

    The Static Keyword

    Because static methods are callable without an instance of the object created, the pseudo-variable $this is not available inside the method declared as static.

    Static properties cannot be accessed through the object using the arrow operator ->.

    Calling non-static methods statically generates an E_STRICT level warning.

    Just because you can call non-static methods statically doesn't mean you should. It's bad form.

提交回复
热议问题