PHP 8.5: xml_parser_free function deprecated as it is no-op in PHP >= 8.0

Version8.5
TypeDeprecation

The xml_parser_free function from the xml extension is used to free an XML parser instance. As part of PHP's resource to object migration, the xml extension's resource objects were migrated to XMLParser objects.

The xml_parser_create function returns an XMLParser object that can be used to parse XML documents, set options, etc. Prior to PHP 8.0, it returned a resource object instead of an XMLParser object. PHP's resource objects need to be freed manually with the xml_parser_free function or let the PHP engine clean them up when the execution finishes.

After the migration to XMLParser objects in PHP 8.0, it was no longer necessary to call xml_parser_free function because XMLParser objects are destroyed when they fall out of scope. Since PHP 8.0, calling the xml_parser_free function had no effect.


In PHP 8.5, the xml_parser_free function is deprecated. Calling it now emits a deprecation notice:

$parser = xml_parser_create();
xml_parser_free($parser);
Function xml_parser_free() is deprecated since 8.5, as it has no effect since PHP 8.0

Recommended Replacement

On PHP applications and libraries that require PHP 8.0 or later, it the xml_parser_free function call can be dropped safely. Because it had no effect since PHP 8.0, this change is backward-compatible on PHP versions >= 8.0.

Applications that need to support PHP 5 and 7 series can conditionally call the xml_parser_free function after checking the PHP version:

- xml_parser_free($parser);
+ PHP_VERSION_ID < 80000 && xml_parser_free($f); 

xml_parser_free RFC Implementation