在 F3 中捕获 LDAP 连接失败

Catch LDAP connection failure in F3

我在 Fat-Free Framework (F3) 中使用 Auth class 来验证来自 OpenLDAP 的用户。但是,应用程序无法捕获 Auth class 构造函数生成的 LDAP connection failure 等错误。

有没有办法捕获此类错误并向用户隐藏详细的堆栈跟踪信息?

参考: https://fatfreeframework.com/3.6/auth

class 抛出一个错误,而不是一个异常,因此它是不可捕获的。

不过,您可以使用静默 @ 运算符跳过错误并检查结果类型(应该是布尔值):

 $res=@$auth->login('login','pass');
 if ($res===TRUE) {
   // login successful
 } elseif ($res===FALSE) {
   // wrong credentials
 } else {
   // LDAP connection failure
 }

如果您只是想对用户隐藏调试堆栈跟踪,则只需将 DEBUG 设置为 0。