gpt4 book ai didi

php - 检查常量是否为空

转载 作者:行者123 更新时间:2023-12-03 00:28:15 25 4
gpt4 key购买 nike

为什么这是不可能的?

if(!empty( _MY_CONST)){
...

但是这是:

$my_const = _MY_CONST;
if(!empty($my_const)){
...
<小时/>
define( 'QUOTA_MSG' , '' ); // There is currently no message to show

$message = QUOTA_MSG;
if(!empty($message)){
echo $message;
}

我只是想通过引用常量本身来使其更简洁。

最佳答案

请参阅manual : empty() 是一种语言构造,而不是函数。

empty() only checks variables as anything else will result in a parse error. In other words, the following will not work: empty(trim($name)).

所以你必须使用一个变量 - empty() 真的是你想要的吗?例如,当常量值为“0”时,它将返回 true。

也许您需要使用 define() 来测试常量是否存在?

关于php - 检查常量是否为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6187234/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com