时时商务社区

标题: php类常量用法实例分析 [打印本页]

作者: 网络通达    时间: 2018-2-14 05:44

            本文实例讲述了php类常量用法。分享给大家供大家参考。具体如下:
getConstant(), '
';
echo $obj->getConstantValue(), '
';
echo Foo::getConstantValue();
// 以上均输出bar
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
希望本文所述对大家的php程序设计有所帮助。
            
            
您可能感兴趣的文章:
  • PHP面向对象的进阶学习(抽像类、接口、final、类常量)
  • 探讨PHP中OO之静态关键字以及类常量的详解
  • php类常量的使用详解
  • PHP面向对象程序设计之类常量用法实例
  • php 类中的常量、静态属性、非静态属性的区别
            




    欢迎光临 时时商务社区 (http://bbs.4435.cn/) Powered by Discuz! X3.2