“::”语法是什么意思


What does "::" syntax mean?

可能的重复项:
参考 - 这个符号在 PHP 中是什么意思?

在PHP中::是什么意思?例如

Pagination::set_config($config);

它类似于=>吗?

它被称为范围解析运算符。

http://php.net/manual/en/keyword.paamayim-nekudotayim.php

在PHP中,它是作用域解析运算符。它用于访问未启动类的方法和属性。为此表示法显式提供的方法称为静态方法

此外,您可以使用此表示法相对地遍历扩展类(从您所在的位置(。例:

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();
?>

只需阅读示例中的注释即可。有关详细信息,请转到 php.net 文章。

::是一个范围解析运算符(最初在 C++ 中这样命名(意味着您将 set_config($config) 方法与类 Pagination 相关联。它是一个静态方法,静态方法不能通过其类的对象访问,因为它们与它们的类相关联,而不是与该类的对象相关联。

Pagination::set_config($config);

表示法 -> 用于访问实例成员。符号=>与 PHP 中的关联数组一起使用,以访问这些数组的成员。