1 class MyClass { 2 const CONST_VALUE = 'A constant value'; 3 4 function canClassBeAutloaded() { 5 echo 111; 6 } 7 } 8 9 $classname = 'MyClass'; 10 echo $classname::CONST_VALUE; // 自 PHP 5.3.0 起 11 12 echo MyClass::canClassBeAutloaded();
1 class A { 2 3 public static $B = '1'; # Static class variable. 4 5 const B = '2'; # Class constant. 6 7 public static function B() { # Static class function. 8 return '3'; 9 } 10 11 } 12 13 echo A::$B . A::B . A::B(); # Outputs: 123
class MyClass { const CONST_VALUE = 'A constant value'; function canClassBeAutloaded() { echo 111; } }
$classname = 'MyClass';echo $classname::CONST_VALUE; // 自 PHP 5.3.0 起
echo MyClass::canClassBeAutloaded();