可能重复:
Reference - What does this symbol mean in PHP?“::”语法是什么意思?
在PHP是什么::
是什么意思?例如
Pagination::set_config($config);
它是否类似于=>
?
可能重复:
Reference - What does this symbol mean in PHP?“::”语法是什么意思?
在PHP是什么::
是什么意思?例如
Pagination::set_config($config);
它是否类似于=>
?
它被称为作用域分辨率运算符。
::
是范围解析操作(原名所以在C++)意味着你的set_config($config)
方法与类Pagination
关联。这是一种静态方法,静态方法不能通过它的类的对象来访问,因为它们与它们的类而不是该类的对象相关联。
Pagination::set_config($config);
符号 - >用于访问实例成员。符号=>
与PHP中的关联数组一起用于访问这些数组的成员。
在PHP中是Scope Resolution Operator。它用于访问未启动类的方法和属性。对这种表示法明确的方法称为静态方法。
此外,您可以使用此表示法相对(从您所在的位置)遍历扩展类。例如:
class betterClass extends basicClass {
protected function doTheMagic() {
$result = parent::doTheMagic();
echo "this will output the result: " . $result;
return $result;
}
}
在这个例子中doTheMagic方法将覆盖它的父的现有的方法,但用parent::doTheMagic();
原始方法可以被调用,不过。
该“::” - 语法被称为示波器分辨率运算符。
它用于引用基类或类中尚未得到任何实例的函数和变量。从php.net
实施例:
<?php
class A {
function example() {
echo "I am the original function A::example().<br />\n";
}
}
class B extends A {
function example() {
echo "I am the redefined function B::example().<br />\n";
A::example();
}
}
// there is no object of class A.
// this will print
// I am the original function A::example().<br />
A::example();
// create an object of class B.
$b = new B;
// this will print
// I am the redefined function B::example().<br />
// I am the original function A::example().<br />
$b->example();
?>
刚读入的例子的评论。有关更多信息,请转至the php.net article。
::的名称是Paamayim Nekudotayim。 – Armin
@戈登 - 感谢 - SO搜索框中的各种搜索未能回答我的问题。 – diagonalbatman
@ThinkingMonkey - 我没有倒下你!而且我搜索过......只是没有“击中”正确的术语。 – diagonalbatman