You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
572 B
31 lines
572 B
<?php
|
|
|
|
/**
|
|
* 类里面的常量
|
|
*/
|
|
|
|
use classA as GlobalClassA;
|
|
|
|
class classA
|
|
{
|
|
//定义类常量
|
|
const a='hello';
|
|
|
|
function func()
|
|
{
|
|
//在类的方法中调用类常量
|
|
echo self::a.'<br>';
|
|
}
|
|
}
|
|
|
|
//直接调用类常量
|
|
echo classA::a.'<br>';
|
|
|
|
//对象::类常量
|
|
$obj = new ClassA();
|
|
echo $obj::a.'<br>';
|
|
echo $obj->a.'<br>'; //对象不能访问类常量,会报“Undefined property: classA::$a”
|
|
|
|
//对象中方法调用类常量
|
|
echo $obj->func();
|
|
?>
|