libxml_use_internal_errors()

libxml_use_internal_errors() — Disable libxml errors and allow user to fetch error information as needed.

Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.1.0, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

libxml_use_internal_errors() allows you to disable standard libxml errors and enable user error handling.

Signature

libxml_use_internal_errors(?bool $use_errors = null): bool

Parameters

ParameterTypeWhat it takes
$use_errors?boolEnable (true) user error handling or disable (false) user error handling. Disabling will also clear any existing libxml errors.

Return value

This function returns the previous value of use_errors.

Example

A runnable snippet:

// enable user error handling var_dump(libxml_use_internal_errors(true)); // load the document $doc = new DOMDocument; if (!$doc->load('file.xml')) { foreach (libxml_get_errors() as $error) { // handle errors here } libxml_clear_errors(); }

Output:

bool(false)

Changelog

VersionChange
8.0.0use_errors is nullable now. Previously, its default was false.

See also

libxml_clear_errors(), libxml_get_errors()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page libxml_use_internal_errors() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.