Skip to content

Commit 9b43f41

Browse files
committed
Fix GH-17158: pg_fetch_result Shows Incorrect ArgumentCountError Message when Called With 1 Argument
1 parent 1862aff commit 9b43f41

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

.github/actions/test-linux/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ runs:
5050
--offline \
5151
--show-diff \
5252
--show-slow 1000 \
53-
--set-timeout 120
53+
--set-timeout 120 ext/pgsql

ext/pgsql/pgsql.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,22 +1705,17 @@ PHP_FUNCTION(pg_fetch_result)
17051705
pgsql_result_handle *pg_result;
17061706
int pgsql_row;
17071707

1708-
if (ZEND_NUM_ARGS() == 2) {
1709-
ZEND_PARSE_PARAMETERS_START(2, 2)
1710-
Z_PARAM_OBJECT_OF_CLASS(result, pgsql_result_ce)
1711-
Z_PARAM_STR_OR_LONG(field_name, field_offset)
1712-
ZEND_PARSE_PARAMETERS_END();
1713-
} else {
1714-
ZEND_PARSE_PARAMETERS_START(3, 3)
1715-
Z_PARAM_OBJECT_OF_CLASS(result, pgsql_result_ce)
1708+
ZEND_PARSE_PARAMETERS_START(2, 3)
1709+
Z_PARAM_OBJECT_OF_CLASS(result, pgsql_result_ce)
1710+
if (ZEND_NUM_ARGS() == 2) {
17161711
if (zend_string_equals_literal(EG(current_execute_data)->func->common.function_name, "pg_result")) {
17171712
Z_PARAM_LONG(row)
17181713
} else {
17191714
Z_PARAM_LONG_OR_NULL(row, row_is_null)
17201715
}
1721-
Z_PARAM_STR_OR_LONG(field_name, field_offset)
1722-
ZEND_PARSE_PARAMETERS_END();
1723-
}
1716+
}
1717+
Z_PARAM_STR_OR_LONG(field_name, field_offset)
1718+
ZEND_PARSE_PARAMETERS_END();
17241719

17251720
pg_result = Z_PGSQL_RESULT_P(result);
17261721
CHECK_PGSQL_RESULT(pg_result);

ext/pgsql/tests/gh17158.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
GH-17158 (pg_fetch_result Shows Incorrect ArgumentCountError Message when Called With 1 Argument)
3+
--EXTENSIONS--
4+
pgsql
5+
--SKIPIF--
6+
<?php include("skipif.inc"); ?>
7+
--FILE--
8+
<?php
9+
10+
include('config.inc');
11+
12+
$db = pg_connect($conn_str);
13+
14+
$result = pg_query($db, "SELECT * FROM ".$table_name.";");
15+
try {
16+
pg_fetch_result($result);
17+
} catch (ArgumentCountError $e) {
18+
echo $e->getMessage(), "\n";
19+
}
20+
21+
pg_free_result($result);
22+
pg_close($db);
23+
24+
?>
25+
--EXPECT--
26+
pg_fetch_result() expects 2 or 3 arguments, 1 given

0 commit comments

Comments
 (0)