Can you tell me about the :: operator in PHP?
thanks,
Hung.
:: Operator
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
It calls a function in your class statically (i.e. outside of Object context so $this doesn't exist) which basically makes it stateless. In PHP5 you can access static class variables with it too.
PHP4
PHP5
http://uk.php.net/manual/en/language.oo ... otayim.php
PHP4
Code: Select all
class Foo
{
function doSomething() {}
}
echo Foo::doSomething();Code: Select all
class Foo
{
public static function doSomething() {}
}
echo Foo::doSomething();It also has a pseudo use for calling parent object methods/properties where you have overloaded with a child class, a good example is the constructor. (php5 example below)
Code: Select all
class Parent
{
public function __construct()
{
$this->doSomething();
}
}
class Child extends Parent
{
public function __construct()
{
parent::__construct();
}
}
$foo = new Child; // doSomething() is executed.