[php-src] master: Clear the libxml last error in libxml_use_internal_errors(false)

From: Date: Wed, 14 Oct 2026 20:46:15 +0000
Subject: [php-src] master: Clear the libxml last error in libxml_use_internal_errors(false)
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-142290@lists.php.net to get a copy of this message
Author: lacatoire (lacatoire) Committer: ndossche (ndossche) Date: 2026-10-14T22:46:03+02:00 Commit: https://github.com/php/php-src/commit/b2163be5ff10a4347b314ee8cecf2866138e3d7a Raw diff: https://github.com/php/php-src/commit/b2163be5ff10a4347b314ee8cecf2866138e3d7a.diff Clear the libxml last error in libxml_use_internal_errors(false) libxml_use_internal_errors(false) destroyed the internal error list but left libxml's own last error in place. libxml_get_last_error() falls back to it once the list is gone, so it kept returning an error while libxml_get_errors() was empty, although the documentation says that disabling clears the existing errors. Reset the last error when the list is destroyed. Calling the function again while the internal errors are already disabled leaves it alone. Closes GH-24295. Changed paths: A ext/libxml/tests/libxml_use_internal_errors_clears_last_error.phpt M NEWS M ext/libxml/libxml.c Diff: diff --git a/NEWS b/NEWS index a93cb03247e7..67c44a4420e9 100644 --- a/NEWS +++ b/NEWS @@ -40,6 +40,10 @@ PHP NEWS encoding used for percent-encoding, the URLSearchParams tail pointer and fragment serialization without a query. (alexandre-daubois) +- LibXML: + . Clear the libxml last error in libxml_use_internal_errors(false). + (lacatoire) + - MBString: . Fixed bug GH-23106 (mb_strpos() reads past the end of a haystack ending in a truncated UTF-8 sequence). (Lazizbek Ergashev) diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c index e53746379428..489dea577105 100644 --- a/ext/libxml/libxml.c +++ b/ext/libxml/libxml.c @@ -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); diff --git a/ext/libxml/tests/libxml_use_internal_errors_clears_last_error.phpt b/ext/libxml/tests/libxml_use_internal_errors_clears_last_error.phpt new file mode 100644 index 000000000000..a0a40d100a63 --- /dev/null +++ b/ext/libxml/tests/libxml_use_internal_errors_clears_last_error.phpt @@ -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)

« previous php.cvs (#142290) next »