Skip to content

Commit 9d04ee8

Browse files
nielsdoscharmitro
authored andcommitted
Fix phpGH-17158: pg_fetch_result Shows Incorrect ArgumentCountError Message when Called With 1 Argument
Closes phpGH-17161.
1 parent 0a2e587 commit 9d04ee8

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ PHP NEWS
2121
- Opcache:
2222
. opcache_get_configuration() properly reports jit_prof_threshold. (cmb)
2323

24+
- PgSql:
25+
. Fixed bug GH-17158 (pg_fetch_result Shows Incorrect ArgumentCountError
26+
Message when Called With 1 Argument). (nielsdos)
27+
2428
- SimpleXML:
2529
. Fixed bug GH-17040 (SimpleXML's unset can break DOM objects). (nielsdos)
2630

ext/pgsql/pgsql.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,7 @@ PHP_FUNCTION(pg_fetch_result)
18931893
Z_PARAM_OBJECT_OF_CLASS(result, pgsql_result_ce)
18941894
Z_PARAM_STR_OR_LONG(field_name, field_offset)
18951895
ZEND_PARSE_PARAMETERS_END();
1896-
} else {
1896+
} else if (ZEND_NUM_ARGS() == 3) {
18971897
ZEND_PARSE_PARAMETERS_START(3, 3)
18981898
Z_PARAM_OBJECT_OF_CLASS(result, pgsql_result_ce)
18991899
if (zend_string_equals_literal(EG(current_execute_data)->func->common.function_name, "pg_result")) {
@@ -1903,6 +1903,9 @@ PHP_FUNCTION(pg_fetch_result)
19031903
}
19041904
Z_PARAM_STR_OR_LONG(field_name, field_offset)
19051905
ZEND_PARSE_PARAMETERS_END();
1906+
} else {
1907+
zend_wrong_parameters_count_error(2, 3);
1908+
RETURN_THROWS();
19061909
}
19071910

19081911
pg_result = Z_PGSQL_RESULT_P(result);

ext/pgsql/tests/gh17158.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
GH-17158 (pg_fetch_result Shows Incorrect ArgumentCountError Message when Called With 1 Argument)
3+
--EXTENSIONS--
4+
pgsql
5+
--FILE--
6+
<?php
7+
8+
try {
9+
pg_fetch_result(null);
10+
} catch (ArgumentCountError $e) {
11+
echo $e->getMessage(), "\n";
12+
}
13+
14+
?>
15+
--EXPECT--
16+
pg_fetch_result() expects at least 2 arguments, 1 given

0 commit comments

Comments
 (0)