dtt83024 2014-06-11 09:22
浏览 298
已采纳

检查是否存在类常量

How can I check if a constant is defined in a PHP class?

class Foo {
    const BAR = 1;
}

Is there something like property_exists() or method_exists() for class constants? Or can I just use defined("Foo::BAR")?

  • 写回答

4条回答 默认 最新

  • dsfhe34889789708 2014-06-11 09:26
    关注

    Yes, just use the class name in front of the constant name.

    http://www.php.net/manual/en/function.defined.php#106287

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面