PHP中双冒号和箭头运算符之间的区别?
2022-08-30 09:20:04
在 php Web 手册的侧边栏中,链接文本 addChild 方法使用范围解析运算符,但在示例中它使用 Arrow 运算符。谁能告诉我为什么会这样?::
在 php Web 手册的侧边栏中,链接文本 addChild 方法使用范围解析运算符,但在示例中它使用 Arrow 运算符。谁能告诉我为什么会这样?::
::
用于静态元素,而用于实例元素。->
例如:
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();
箭头表示 addChild 作为对象的成员被调用(在本例中为 $sxe)。
双冒号表示 addChild 是 SimpleXMLElement 类的成员。