类常量访问权限控制
class ConstDemo
{
// 常量默认为 public
const PUBLIC_CONST_A = 1;
// 可以自定义常量的可见范围
public const PUBLIC_CONST_B = 2;
protected const PROTECTED_CONST = 3;
private const PRIVATE_CONST = 4;
// 多个常量同时声明只能有一个属性
private const FOO = 1, BAR = 2;
}
class ConstDemo1 extends ConstDemo
{
public function __construct() {
echo self::PUBLIC_CONST_A;
echo self::PUBLIC_CONST_B;
echo self::PROTECTED_CONST;
echo self::PRIVATE_CONST;
}
}
new ConstDemo1();Last updated