php - PHP禁止第三方库警告

标签 php error-handling

我正在使用CentralNIC(https://github.com/centralnic/php-epp/)的NET_EPP库
在某些时候我的脚本调用

@$frame = new \Net_EPP_Frame_Command_Login(); //the EPP framework throws a warning otherwise    

注意@在行的开头,这样做是为了抑制第3方库在此处引发的警告。

因此,Net_EPP_Frame_Command_Login的构造函数调用其父构造函数
class Net_EPP_Frame_Command_Login extends Net_EPP_Frame_Command {
    function __construct() {
        parent::__construct('login');

看起来像
class Net_EPP_Frame_Command extends Net_EPP_Frame {

        function __construct($command, $type) {
            $this->type = $type;

这部分反过来向我抛出2条警告-
WARNING: Missing argument 2 for Net_EPP_Frame_Command::__construct()
NOTICE: Undefined variable: type

如何在不修改库的情况下禁止显示这些警告?

更新

有趣的是,如果我直接与服务器通信,它不会显示警告,尽管如果我使用curl获取页面内容,它也会显示警告。
$args = array("domainName" => $_POST['domain'], "tld" => $_POST['tld']);
$action = "CheckAvailabilityActionByModule";
$msg = new CommsMessage($action,$args);
$reply = TestServer::main($msg->encode());
$reply = CommsMessage::decodeReply($reply);

当我直接与服务器对话时,效果很好。但
$reply = $client->getAvailabilityByModule($_POST['domain'], $_POST['tld']);

不是因为此请求是通过curl完成的

最佳答案

您可以更改error_reporting(但不更改所有警告或通知):

error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));

或设置自己的error handler。在这种情况下,error_reporting设置将无效:
set_error_handler("myErrorHandler");

function myErrorHandler($errno, $errstr, $errfile, $errline) {
    // do what you want in case of error

    /* Don't execute PHP internal error handler */
    return true;
}

关于php - PHP禁止第三方库警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17863183/

相关文章:

javascript - 错误验证在 AngularJS 中不起作用

php - facebook API 有什么好的 totuiral 吗?是否有可能在我的网站上获取用户的好友列表?

php - 使用 php 从字符串中查找文件名

html - 406在HTML网站上 Not Acceptable

python - 异常处理程序,用于检查变量的内联脚本是否有效

python-3.x - 使用resample时出错,即使我曾经使用过to_datetime和set_index, 'only valid with datetimeindex'还是说

javascript - 将php倒计时变成javascript

php - phpexcel中的单元格格式

php - 上传文件限制

python - 在python中将数据追加到文件中时复制数据