Friday 20 December 2013

Scope Resolution Operator in PHP

The Scope Resolution Operator :

in simpler terms, the double colon, is a token that allows access to static, constant, and overridden properties or methods of a class.
When referencing these items from outside the class definition, use the name of the class.

Example: 


<?php
class MyClass
{
const CONST_VALUE = 'A constant value';
}
$classname = 'MyClass';
echo $classname::CONST_VALUE; // As of PHP 5.3.0
echo MyClass::CONST_VALUE;
?>

Output:

A constant value
A constant value

#Anbu.A

1 comment: