This article mainly introduces PHP examples and analyzes the concept of class constants in PHP. Interested friends can refer to it. I hope it will be helpful to everyone.
The examples in this article describe the usage of PHP class constants, as follows:
'; echo Foo::BAR, '
'; $obj = new Foo(); echo $obj->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
Summary:The above is the entire content of this article, I hope it can be helpful to everyone's learning help.
Related recommendations:
How to use and introduce the PHP Closure class
Get Chinese pinyin in the php program The first letter of the method
php three ways to clear the session
The above is the detailed content of PHP example analyzes the concept of class constants in PHP. For more information, please follow other related articles on the PHP Chinese website!