gpt4 book ai didi

PHP exit() 与 if - else 语句

转载 作者:行者123 更新时间:2023-12-02 07:43:23 25 4
gpt4 key购买 nike

验证然后退出() 函数或将验证的整个结果包装在 if 语句中是好的还是坏的做法?示例

function foo($uid)
{

$allowed = $auth->checkIfAllowed($uid);

if ($allowed == false) exit();

//continue with senstive code here

}
}

function foo($uid)
{

$allowed = $auth->checkIfAllowed($uid);

if ($allowed == true)
{
// do sensitive stuff
}
}

最佳答案

我想借此机会谈谈 exit;(正如其他人所说,两者都有效,第二个比第一个更明确,并让您有机会发送一个很好的错误消息给用户)。我的主要不满(我有几个 exit;)是人们应该停止在库中使用它,即可以/将在其他项目中使用的代码......你知道调试这些有多烦人吗?抛出异常,触发 fatal error ,但给我东西和描述。

/咆哮

关于PHP exit() 与 if - else 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8866637/

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