class InputCheck
{
const NOT_INPUT = "%sRequired";
public function inList ($msg = null)
{
print_r(self::$msg);exit;
}
}
(new InputCheck())->inList('NOT_INPUT');
在此类中,我定义了一个名称为NOT_INPUT
的常量。其中一种方法接受包含该常量名称的字符串。如何使用该值动态访问类常量?
请参见下面有关如何访问类常量的信息。
class InputCheck
{
const NOT_INPUT = "%sRequired";
public function inList ($msg = null)
{
echo self::NOT_INPUT; //Access the Constant here.
print_r($msg);exit;
}
}