php的常量操作类库.zip

时间:2022-07-31 04:19:34
【文件属性】:
文件名称:php的常量操作类库.zip
文件大小:2KB
文件格式:ZIP
更新时间:2022-07-31 04:19:34
类库下载-php的常量操作类库 <?php class Foo {   const BAR = 'bar';   public static function getConstantValue()   {     return self::BAR;   }   public function getConstant()   {     return self::BAR;   } } $foo = 'Foo'; echo $foo::BAR, ''; echo Foo::BAR, ''; $obj = new Foo(); echo $obj->getConstant(), ''; echo $obj->getConstantValue(), ''; echo Foo::getConstantValue(); class Bar extends Foo {   const BAR = 'foo';    public static function getMyConstant()   {     return self::BAR;   }   public static function getParentConstant()   {     return parent::BAR;   } } echo Bar::getMyConstant(); // foo echo Bar::getParentConstant(); // bar类常量属于类自身,不属于对象实例,不能通过对象实例访问不能用public,protected,private,static修饰子类可以重写父类中的常量,可以通过(parent::)来调用父类中的常量 自PHP5.3.0起,可以用一个变量来动态调用类。但该变量的值不能为关键字
【文件预览】:
php的常量操作类库
----dingyi.php(1KB)
----php中文网下载站.url(114B)
----php中文网免费下载站.txt(219B)

网友评论