("CONSTANT", "Hello world.");
echo CONSTANT; // outputs "Hello world."
echo Constant; // outputs "Constant" and issues a notice.
如果定义的常量在类内部,则应当且必须这样写(参考:http://i.92wy.com/personal_blog_show.aspx?id=39341)
class MyClass
{ const constant = 'constant value';
function showConstant() { echo self::constant."\n"; }
}
echo MyClass::constant."\n";
$class = new MyClass();
$class->showConstant();// echo $class::constant; is not allowed
No comments:
Post a Comment