PHP支持第三方库警告


PHP supress 3rd party library warning

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

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

注意,在行的开头,这样做是为了抑制第三方库在此处抛出的警告。

因此,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_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;
}

有关详细信息,请查看http://php.net/manual/en/function.error-reporting.php关闭所有错误报告。

error_reporting(0); 

要么给两个参数一个值,要么从__construct函数中删除一个值。