PHP中双冒号和箭头运算符之间的区别?
问题描述:
在php网络手册的边栏中,链接文本 addChild方法使用::
范围解析运算符,但是在示例中,它使用Arrow运算符.谁能告诉我为什么?
In the sidebar of the php web manual, link text the addChild method uses the ::
scope resolution operator, but in the example it uses the Arrow operator. Can anyone tell me why that is?
答
::
用于静态元素,而->
用于实例元素.
::
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();