From c767049dbac5a52115c667504b111d2050d8079c Mon Sep 17 00:00:00 2001 From: lacatoire Date: Mon, 17 Aug 2026 22:30:32 +0200 Subject: [PATCH 1/3] Fix wrong argument number in fsockopen/pfsockopen timeout error php_fsockopen_stream() called zend_argument_value_error(6, ...) for the $timeout parameter, but $timeout is the 5th argument. This caused the error message to show "Argument #6" with no parameter name, since get_function_arg_name() returns NULL when arg_num exceeds the actual argument count. Reproduce: fsockopen('localhost', 80, $err, $errstr, -2.0); // Before: ValueError: fsockopen(): Argument #6 must be -1 or between... // After: ValueError: fsockopen(): Argument #5 ($timeout) must be -1... --- ext/standard/fsock.c | 2 +- .../fsockopen_timeout_out_of_range.phpt | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 ext/standard/tests/network/fsockopen_timeout_out_of_range.phpt diff --git a/ext/standard/fsock.c b/ext/standard/fsock.c index 0b27a13e624c..700ee3bb5311 100644 --- a/ext/standard/fsock.c +++ b/ext/standard/fsock.c @@ -103,7 +103,7 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent) efree(hashkey); } - zend_argument_value_error(6, "must be -1 or between 0 and " ZEND_ULONG_FMT, ((double) PHP_TIMEOUT_ULL_MAX / 1000000.0)); + zend_argument_value_error(5, "must be -1 or between 0 and " ZEND_ULONG_FMT, ((double) PHP_TIMEOUT_ULL_MAX / 1000000.0)); RETURN_THROWS(); } else { #ifndef PHP_WIN32 diff --git a/ext/standard/tests/network/fsockopen_timeout_out_of_range.phpt b/ext/standard/tests/network/fsockopen_timeout_out_of_range.phpt new file mode 100644 index 000000000000..e6bd9e677eb3 --- /dev/null +++ b/ext/standard/tests/network/fsockopen_timeout_out_of_range.phpt @@ -0,0 +1,19 @@ +--TEST-- +fsockopen() and pfsockopen(): ValueError for $timeout reports correct argument number and name +--FILE-- +getMessage(), "\n"; +} + +try { + pfsockopen('localhost', 80, $errno, $errstr, -2.0); +} catch (ValueError $e) { + echo $e->getMessage(), "\n"; +} +?> +--EXPECTF-- +fsockopen(): Argument #5 ($timeout) must be -1 or between 0 and %s +pfsockopen(): Argument #5 ($timeout) must be -1 or between 0 and %s From 80370d2037cc64d1582be4851a493881177c1971 Mon Sep 17 00:00:00 2001 From: Louis-Arnaud Date: Tue, 18 Aug 2026 17:11:40 +0200 Subject: [PATCH 2/3] Update ext/standard/tests/network/fsockopen_timeout_out_of_range.phpt Co-authored-by: NickSdot <32384907+NickSdot@users.noreply.github.com> --- .../network/fsockopen_timeout_out_of_range.phpt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ext/standard/tests/network/fsockopen_timeout_out_of_range.phpt b/ext/standard/tests/network/fsockopen_timeout_out_of_range.phpt index e6bd9e677eb3..575db4690fb9 100644 --- a/ext/standard/tests/network/fsockopen_timeout_out_of_range.phpt +++ b/ext/standard/tests/network/fsockopen_timeout_out_of_range.phpt @@ -4,16 +4,16 @@ fsockopen() and pfsockopen(): ValueError for $timeout reports correct argument n getMessage(), "\n"; +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { pfsockopen('localhost', 80, $errno, $errstr, -2.0); -} catch (ValueError $e) { - echo $e->getMessage(), "\n"; +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } ?> --EXPECTF-- -fsockopen(): Argument #5 ($timeout) must be -1 or between 0 and %s -pfsockopen(): Argument #5 ($timeout) must be -1 or between 0 and %s +ValueError: fsockopen(): Argument #5 ($timeout) must be -1 or between 0 and %s +ValueError: pfsockopen(): Argument #5 ($timeout) must be -1 or between 0 and %s From 7ba8da48dcb1cdea6621ea04a5f0d9f9ef6bfafb Mon Sep 17 00:00:00 2001 From: lacatoire Date: Tue, 18 Aug 2026 17:14:24 +0200 Subject: [PATCH 3/3] Adjust gh14780 expectations to the corrected argument number --- ext/standard/tests/streams/gh14780.phpt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/standard/tests/streams/gh14780.phpt b/ext/standard/tests/streams/gh14780.phpt index 064e496b1753..c0fc4e621a9d 100644 --- a/ext/standard/tests/streams/gh14780.phpt +++ b/ext/standard/tests/streams/gh14780.phpt @@ -31,8 +31,8 @@ try { } ?> --EXPECTF-- -pfsockopen(): Argument #6 must be -1 or between 0 and %s -pfsockopen(): Argument #6 must be -1 or between 0 and %s +pfsockopen(): Argument #5 ($timeout) must be -1 or between 0 and %s +pfsockopen(): Argument #5 ($timeout) must be -1 or between 0 and %s resource(%d) of type (persistent stream) -pfsockopen(): Argument #6 must be -1 or between 0 and %s -pfsockopen(): Argument #6 must be -1 or between 0 and %s +pfsockopen(): Argument #5 ($timeout) must be -1 or between 0 and %s +pfsockopen(): Argument #5 ($timeout) must be -1 or between 0 and %s