Possible Duplicate:
Reference - What does this symbol mean in PHP?

In PHP what does :: mean? e.g

Pagination::set_config($config);

Is it analogous to => ?

有帮助吗?

解决方案

It is called Scope Resolution Operator.

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

其他提示

In PHP it is the Scope Resolution Operator. It is used to access methods and attributes of uninitiated classes. Methods which are made explicit for this notation are called static methods.

Furthermore you can use this notation to traverse through extended classes relatively (from the position where you are). Example:

class betterClass extends basicClass {
    protected function doTheMagic() {
       $result = parent::doTheMagic();
       echo "this will output the result: " . $result;
       return $result;
    }
}

In this example the doTheMagic method overwrites the existing method of its parent, but with parent::doTheMagic(); the original method can be called, nevertheless.

This "::"-syntax is called Scope Resolution Operator.

It's used to refer to function and variables in base classes or classes that haven't got any instances yet.

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

Just read the comments in the example. For more information, go to the php.net article.

:: is a scope resolution operator (originally named so in C++) means you're associating theset_config($config) method with the class Pagination. It's a static method and static methods can not be accessed through the objects of it's class, since they are associated with their class rather than the objects of that class.

Pagination::set_config($config);

The notation -> is used to access instance members. The notation => is used with associative arrays in PHP to access the members of those arrays.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top