In PHP, xml_parser_free() is a legacy function that used to release an XML parser from memory.
Before PHP 8 the parser was a resource that had to be freed by hand. In PHP 8 the parser is an XMLParser object, so PHP cleans it up on its own when nothing uses it anymore. The function is usually unnecessary today.
Syntax
Call xml_parser_free() with the values you need. Start with this line.
PHP
xml_parser_free($parser);
Call
What it does
xml_parser_free($parser)
Legacy call that returns true. It does nothing useful in PHP 8.
unset($parser)
The modern way to let go of the parser, so the object can be cleaned up.
$parser = null
Another way to drop the reference when you are finished.
In PHP 8 xml_parser_free() does not destroy the object. It is kept only for old code. Newer PHP versions (8.5 and later) mark the function as deprecated, so you can safely leave it out of new code.
Library declarations
PHP
xml_parser_free(XMLParser $parser): bool
Parameters
Parameter
Description
parser
Required. The XMLParser object created by xml_parser_create() or xml_parser_create_ns().
Return Value
Return Value
Description
bool
true on success. It can return false with a warning when called while the parser is still parsing.
PHP Examples
Example 1 — The Legacy Call
Older tutorials free the parser after parsing. On PHP 8.0 to 8.4 it still works and returns true. A version check keeps the example safe on newer releases.