From 388f63c310f45064fc1faaa20efe2217e37c8c96 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sat, 14 Dec 2024 15:52:39 +0100 Subject: [PATCH] Fix GH-17158: pg_fetch_result Shows Incorrect ArgumentCountError Message when Called With 1 Argument Closes GH-17161. --- NEWS | 4 ++++ ext/pgsql/pgsql.c | 5 ++++- ext/pgsql/tests/gh17158.phpt | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 ext/pgsql/tests/gh17158.phpt diff --git a/NEWS b/NEWS index 757cab920c22d..ee7e9614b42ca 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,10 @@ PHP NEWS - Opcache: . opcache_get_configuration() properly reports jit_prof_threshold. (cmb) +- PgSql: + . Fixed bug GH-17158 (pg_fetch_result Shows Incorrect ArgumentCountError + Message when Called With 1 Argument). (nielsdos) + - SimpleXML: . Fixed bug GH-17040 (SimpleXML's unset can break DOM objects). (nielsdos) diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 4087e61670230..1db33e5b18225 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -1710,7 +1710,7 @@ PHP_FUNCTION(pg_fetch_result) Z_PARAM_OBJECT_OF_CLASS(result, pgsql_result_ce) Z_PARAM_STR_OR_LONG(field_name, field_offset) ZEND_PARSE_PARAMETERS_END(); - } else { + } else if (ZEND_NUM_ARGS() == 3) { ZEND_PARSE_PARAMETERS_START(3, 3) Z_PARAM_OBJECT_OF_CLASS(result, pgsql_result_ce) if (zend_string_equals_literal(EG(current_execute_data)->func->common.function_name, "pg_result")) { @@ -1720,6 +1720,9 @@ PHP_FUNCTION(pg_fetch_result) } Z_PARAM_STR_OR_LONG(field_name, field_offset) ZEND_PARSE_PARAMETERS_END(); + } else { + zend_wrong_parameters_count_error(2, 3); + RETURN_THROWS(); } pg_result = Z_PGSQL_RESULT_P(result); diff --git a/ext/pgsql/tests/gh17158.phpt b/ext/pgsql/tests/gh17158.phpt new file mode 100644 index 0000000000000..ade47ededed12 --- /dev/null +++ b/ext/pgsql/tests/gh17158.phpt @@ -0,0 +1,16 @@ +--TEST-- +GH-17158 (pg_fetch_result Shows Incorrect ArgumentCountError Message when Called With 1 Argument) +--EXTENSIONS-- +pgsql +--FILE-- +getMessage(), "\n"; +} + +?> +--EXPECT-- +pg_fetch_result() expects at least 2 arguments, 1 given