::
is for calling a static method on a class:
Foo::bar();
->
is for calling an instance method on an object of a class:
$foo = new Foo;
$foo->bar();
The two are entirely different.
The reason that the manual always refers to methods in the notation Class::method
is that the method is defined as part of a class, and that the notation $obj->method
is even more confusing since $obj
is a variable of an arbitrary name. It's a convention to refer to methods by their "static" class name to make it unambiguous what method of what class you're talking about. You know whether to call the method statically or on an object instance by the presence or absence of the keyword static
in its signature:
public static DateTime DateTime::createFromFormat ( string $format , string $time [, DateTimeZone $timezone ] )
^^^^^^
http://php.net/manual/en/datetime.createfromformat.php
Static method, call like this:
$foo = DateTime::createFromFormat(...);
But:
public DateTime DateTime::add ( DateInterval $interval )
http://php.net/manual/en/datetime.add.php
Not static, call as instance method:
$foo = new DateTime;
$foo->add(...);