Código PHP:
<?php
class MyClass
{
const MY_CONSTANT = "Constant class";
public static function __get($name)
{
if(defined("self::$name"))
{
return constant("self::$name");
}
trigger_error ("Constant $name isn't defined");
}
}
$instance = new MyClass();
echo $instance->MY_CONSTANT; //it works!!
?>