PHP: What if I call a static method in non-static way

后端 未结 3 663
北恋
北恋 2020-12-03 13:43

I\'m not pro in Object Oriented Programming and I got a silly question:

class test {
    public static function doSomething($arg) {
        $foo = \'I ate yo         


        
3条回答
  •  没有蜡笔的小新
    2020-12-03 14:21

    It makes no difference if your method don't use $this and don't access to static properties.

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

    $this is not available inside the method declared as static.

    But, you should always use :: to call a static method, even through php let you call it on an instance.

提交回复
热议问题