且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP中双冒号和箭头运算符之间的区别?

更新时间:2022-05-08 03:29:32

::用于静态元素,而->用于实例元素.

:: is for static elements while -> is for instance elements.

例如:

class Example {
  public static function hello(){
    echo 'hello';
  }
  public function world(){
    echo 'world';
  }
}

// Static method, can be called from the class name
Example::hello();

// Instance method, can only be called from an instance of the class
$obj = new Example();
$obj->world();

有关静态概念的更多信息