phasync
HttpClientOptions / overrideFrom

Method

HttpClientOptions::overrideFrom

Return a copy of this instance with the non-null values of $options applied on top.

Description#

public HttpClientOptions::overrideFrom(
    HttpClientOptions|array|null $options
): HttpClientOptions

A null value never overwrites a set option, so a default cannot be cleared this way. An array value replaces the old array. false and 0 are values like any other.

Parameters#

$options HttpClientOptions|array|null
The values to apply

Return values#

HttpClientOptions

Errors / Exceptions#

ExceptionWhen
InvalidArgumentExceptionFor an option name that is not a property

Examples#

Example 1
$defaults = new HttpClientOptions(['timeoutMs' => 5000, 'headers' => ['Accept: text/html']]);
$one      = $defaults->overrideFrom(['timeoutMs' => 100]);
// $one->timeoutMs is 100, $one->headers is still ['Accept: text/html']; $defaults is unchanged

See also#