PHP中双冒号和箭头运算符之间的区别? [英] Difference between double colon and arrow operators in PHP?
本文介绍了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();
这篇关于PHP中双冒号和箭头运算符之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文