在php web手册的侧栏中,addChild方法使用了::
作用域解析操作符,但在本例中它使用了箭头操作符。有人能告诉我这是为什么吗?
发布于 2010-10-19 01:07:48
::
用于静态元素,而->
用于实例元素。
例如:
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();
发布于 2010-10-19 01:04:37
这只是一个事实的符号,它是一个对象的方法,与实际使用无关。
在文档的情况下,你不是在处理像$object
这样的对象的实例,所以->
操作符是不正确的,因为你想要列出实际的类名。因此,在类名称为static的静态方法的用法之后,您可以使用范围res。操作员::
...
这通常是php文档对类的工作方式。
发布于 2010-10-19 01:06:38
箭头表示作为对象(在本例中为$sxe)的成员调用addChild。
双冒号表示addChild是SimpleXMLElement类的成员。
https://stackoverflow.com/questions/3961456
复制相似问题