php - 允许使用@进行错误抑制的功能

标签 php function error-handling

我感兴趣的是如何创建自己的函数,允许它在没有错误记录的情况下执行,但前提是使用 @ 运算符执行,例如 @function();?

功能:

public function query($sql, $id = false){
    $this->query_id = mysqli_query($this->connection, $sql);
    if(!$this->query_id){
        // I want to suppress this error call here...
        psyo::error("Error while executing query (sql: {$sql}).");
        return NULL;
    }else{
        $this->result = mysqli_store_result($this->connection);
        $this->affected = mysqli_affected_rows($this->connection);
        return $id ? $this->query_id : $this;
    }
}

附言我正在使用我自己的错误处理类,它不是通过 error_log(); 左右操作的。

提前致谢!

最佳答案

我认为没有办法知道确定是否使用了@-operator 来调用函数,但是您可以使用error_reporting() 来测试对于当前级别,当使用 @-operator 时为 0。

function test()
{   
    var_dump(error_reporting());
}

test();
@test();

关于php - 允许使用@进行错误抑制的功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5554862/

相关文章:

php - 长时间运行的 PHP 脚本在通过 exec() 调用时停止,但在通过 CLI 调用时结束

php - 用户登录报表需要用户最新的登录记录

python - Python [Errno 13]-保存用户打开的文件时的异常处理

python - Python回溯错误-写入文本文件

list - 如何将列表转换为 Erlang 中的函数参数?

sharepoint - 如何定向到自定义错误页面?

php - 如何验证用户仅对一个文件输入一条评论? MYSQL PHP

PHP监听unix套接字

javascript - 从 Javascript 函数调用 jQuery 函数

function - Kotlin:获取对类实例函数的引用