Before PHP 8.3 had a
function that supports two function signatures.It can either accept an array of options to be set for one or more contexts or wrappers, or it can accept a single wrapper name, option name, or its value. stream_context_set_option
For the instance
<?php
function stream_context_set_option(
$stream_or_context,
string $wrapper,
string $option,
mixed $value): bool {
}
function stream_context_set_option(
$stream_or_context,
array $options): bool {
}
As part of PHP's efforts to remove overloaded function signatures (functions that support more than one signature), PHP 8.3 introduces a new function
(note the laststream_context_set_options
"s"
) that supports the second signature mentioned above.
Note:
In PHP 8.4, the stream_context_set_option(
$stream_or_context, string $wrapper, string $option, mixed $value)
signature will be deprecated, and PHP 9.0 will remove the
function. stream_context_set_option
stream_context_set_options function signature:
<?php
/**
* @param resource $context The stream or context resource to apply the
* options to
* @param array $options The options to set for `stream_or_context`
* @return bool Returns true success or false on failure.
*/
function stream_context_set_options($context, array $options): bool {
}
It is possible to easily implement the
function in PHP 8.2 and older PHP versions.stream_context_set_options
<?php
if (\PHP_VERSION_ID < 80300) {
/**
* @param resource $context The stream or context resource to apply the options to
* @param array $options The options to set for `stream_or_context`
* @return bool Returns true success or false on failure.
*/
function stream_context_set_options($context, array $options): bool {
return \stream_context_set_option($context, $options);
}
}