如题所述
æ们å¯ä»¥å¨ç±»ä¸å®ä¹å¸¸éã常éçå¼å°å§ç»ä¿æä¸åãå¨å®ä¹å使ç¨å¸¸éçæ¶åä¸éè¦ä½¿ç¨$符å·ã
class MyClass{
const constant = 'constant value';
function showConstant() {
echo self::constant . "\n";
}
}
echo MyClass::constant . "\n";
$classname = "MyClass";
echo $classname::constant . "\n"; // PHP 5.3.0ä¹å
$class = new MyClass();
$class->showConstant();
echo $class::constant."\n"; // PHP 5.3.0ä¹å
温馨提示:答案为网友推荐,仅供参考