How to check if a defined constant exists in PHP?

后端 未结 6 531
一整个雨季
一整个雨季 2020-12-29 19:35

So I\'m using a PHP framework called fuelphp, and I have this page that is an HTML file, so I can\'t use PHP in it. I have another file tha

6条回答
  •  时光取名叫无心
    2020-12-29 19:58

    here's a cooler & more concise way to do it:

    defined('CONSTANT') or define('CONSTANT', 'SomeDefaultValue');
    

    credit: daniel at neville dot tk https://www.php.net/manual/en/function.defined.php#84439

提交回复
热议问题