libxml_set_streams_context()

libxml_set_streams_context() — Set the streams context for the next libxml document load or write.

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

Signature

libxml_set_streams_context(resource $context): void

Parameters

ParameterTypeWhat it takes
$contextresourceThe stream context resource (created with stream_context_create())

Return value

No value is returned.

Example

A runnable snippet:

$opts = [ 'http' => [ 'user_agent' => 'PHP libxml agent', ] ]; $context = stream_context_create($opts); libxml_set_streams_context($context); // request a file through HTTP $dom = new DOMDocument; $doc = $dom->load('http://www.example.com/file.xml');

Changelog

VersionChange
8.4.0libxml_set_streams_context() now throws a TypeError when a non-stream resource is passed to context, instead of throwing later when the context is used.

See also

stream_context_create()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page libxml_set_streams_context() (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.