【问题标题】:error control operator not working错误控制操作员不工作
【发布时间】:2025-12-17 09:40:01
【问题描述】:

我的问题与one 类似。但是,error control operator 对我不起作用。

使用以下代码:

$this->fp = @fsockopen($this->ip, $this->port, $errno, $errstr, $this->timeout);

我仍然收到一条错误消息:

fsockopen(): unable to connect to xxx.xxx.xxx.xx:xxxxx (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. )

我可以禁用错误控制运算符吗?

【问题讨论】:

    标签: php


    【解决方案1】:

    我发现了问题!我一直在使用自己的错误处理程序

    set_error_handler('my_error_handler');
    

    不管@是否有前缀,它都会打印出错误。

    仅供参考 - 来自php manual 的代码演示了如何在用户定义的错误处理程序中抑制错误:

    // if error has been supressed with an @
    if (error_reporting() == 0) {
        return;
    }
    

    【讨论】: