Keywords:

  • const CONST_VALUE = 'A constant value';
  • parent::CONST_VALUE
  • self::CONST_VALUE

Allows access to static, constant, and overridden members or methods of a class. When referencing these items from outside the class definition, use the name of the class.

<?php
class resolution {
const CONST_VALUE = 'A constant value';
}

echo resolution::CONST_VALUE;
?>
<?php
class testClass extends resolution
{
public static $my_static = 'static variables';

public static function res_operator($value) {
echo "<br>";
echo parent::CONST_VALUE . " and local $value <br>";
echo self::$my_static . "<br>";
echo self::CONST_VALUE . "<br>";
}
}
//calling function, without creating an object
testClass::res_operator(15);
//creating an object to input different value
$t = new testClass();
$t->res_operator(10);
?>