Skip to content

Commit

Permalink
Fsockopen: anticipate on PHP 8.4 deprecation of `stream_context_set_o…
Browse files Browse the repository at this point in the history
…ption()` overloaded signature

PHP 8.4 will deprecate the two parameter signature of the `stream_context_set_option()` function.
PHP 8.3 will introduce a replacement function `stream_context_set_options()` (take note of the `s` at the end!) for the two parameter signature.

This commit adds a toggle to the `Fsockopen::request()` method to call the correct PHP function based on its availability.

Refs:
* https://wiki.php.net/rfc/deprecate_functions_with_overloaded_signatures#stream_context_set_option
* https://www.php.net/stream_context_set_option
* (docs for the new function are not yet available)
  • Loading branch information
jrfnl committed Mar 25, 2024
1 parent 4ad772c commit d53d421
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Transport/Fsockopen.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,15 @@ public function request($url, $headers = [], $data = [], $options = []) {
$verifyname = false;
}

stream_context_set_option($context, ['ssl' => $context_options]);
// Handle the PHP 8.4 deprecation (PHP 9.0 removal) of the function signature we use for stream_context_set_option().
// Ref: https://wiki.php.net/rfc/deprecate_functions_with_overloaded_signatures#stream_context_set_option
if (function_exists('stream_context_set_options')) {
// PHP 8.3+.
stream_context_set_options($context, ['ssl' => $context_options]);
} else {
// PHP < 8.3.
stream_context_set_option($context, ['ssl' => $context_options]);
}
} else {
$remote_socket = 'tcp://' . $host;
}
Expand Down

0 comments on commit d53d421

Please sign in to comment.