【问题标题】:PHP: what is the difference between $object::method and $object->method?PHP:$object::method 和 $object->method 有什么区别?
【发布时间】:2013-04-11 08:15:19
【问题描述】:

我总是写:

$object->method

但我经常看到:

$object::method 

有什么区别?

【问题讨论】:

    标签: php class inheritance methods


    【解决方案1】:

    -> 用于引用对象的成员。

    :: 是范围解析运算符,用于引用类的静态成员。例如

    class test {
        public static function vehicle() {
            echo "Bus";
        }
    
        public function automobile() {
            echo "Car";
        }
    }
    

    你会调用函数汽车()为

    $test = new test();
    $test->automobile();
    

    你将调用车辆功能为

    test::vehicle();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-25
      • 1970-01-01
      相关资源
      最近更新 更多