Wednesday, 28 January 2009

::, Scope Resolution Operator, in Php

The Scope Resolution Operator (also called Paamayim Nekudotayim) or in
simpler terms, the double colon, is a token that allows access to
constant, and overridden
members or methods of a class.

When referencing these items from outside the class definition, use
the name of the class.

Example #1 :: from outside the class definition

class MyClass {
CONST_VALUE 'A constant value';

$classname 'MyClass';
$classname::CONST_VALUE// As of PHP 5.3.0

echo MyClass::CONST_VALUE;

And, Static properties cannot be accessed through the object using the arrow
operator ->.

No comments:

My photo
London, United Kingdom

Facebook & Twitter