我正在使用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/