Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ext/libxml/libxml.c
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,9 @@ PHP_FUNCTION(libxml_use_internal_errors)
zend_llist_destroy(LIBXML(error_list));
efree(LIBXML(error_list));
LIBXML(error_list) = NULL;
/* libxml_get_last_error() falls back to libxml's own last error
* once the list is gone, so it must not outlive the cleared list. */
xmlResetLastError();
}
} else {
xmlSetStructuredErrorFunc(NULL, php_libxml_structured_error_handler);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
libxml_use_internal_errors(false) clears the last error
--EXTENSIONS--
libxml
dom
--FILE--
<?php

libxml_use_internal_errors(true);

$document = new DOMDocument();
$document->loadXML('<a><b></a>');

var_dump(count(libxml_get_errors()) > 0);
var_dump(libxml_get_last_error() instanceof LibXMLError);

var_dump(libxml_use_internal_errors(false));

var_dump(libxml_get_errors());
var_dump(libxml_get_last_error());

?>
--EXPECT--
bool(true)
bool(true)
bool(true)
array(0) {
}
bool(false)
Loading