Skip to content

Commit 2309cac

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
2 parents 57eb399 + 0a3442f commit 2309cac

File tree

3 files changed

+99
-8
lines changed

3 files changed

+99
-8
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ PHP NEWS
3939
- PgSql:
4040
. Fixed bug GH-17158 (pg_fetch_result Shows Incorrect ArgumentCountError
4141
Message when Called With 1 Argument). (nielsdos)
42+
. Fixed further ArgumentCountError for calls with flexible
43+
number of arguments. (David Carlier)
4244

4345
- Phar:
4446
. Fixed bug GH-17137 (Segmentation fault ext/phar/phar.c). (nielsdos)

ext/pgsql/pgsql.c

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,14 +1135,17 @@ PHP_FUNCTION(pg_query)
11351135

11361136
link = FETCH_DEFAULT_LINK();
11371137
CHECK_DEFAULT_LINK(link);
1138-
} else {
1138+
} else if (ZEND_NUM_ARGS() == 2) {
11391139
ZEND_PARSE_PARAMETERS_START(2, 2)
11401140
Z_PARAM_OBJECT_OF_CLASS(pgsql_link, pgsql_link_ce)
11411141
Z_PARAM_STRING(query, query_len)
11421142
ZEND_PARSE_PARAMETERS_END();
11431143

11441144
link = Z_PGSQL_LINK_P(pgsql_link);
11451145
CHECK_PGSQL_LINK(link);
1146+
} else {
1147+
zend_wrong_parameters_count_error(1, 2);
1148+
RETURN_THROWS();
11461149
}
11471150

11481151
pgsql = link->conn;
@@ -1233,7 +1236,7 @@ PHP_FUNCTION(pg_query_params)
12331236

12341237
link = FETCH_DEFAULT_LINK();
12351238
CHECK_DEFAULT_LINK(link);
1236-
} else {
1239+
} else if (ZEND_NUM_ARGS() == 3) {
12371240
ZEND_PARSE_PARAMETERS_START(3, 3)
12381241
Z_PARAM_OBJECT_OF_CLASS(pgsql_link, pgsql_link_ce)
12391242
Z_PARAM_STRING(query, query_len)
@@ -1242,6 +1245,9 @@ PHP_FUNCTION(pg_query_params)
12421245

12431246
link = Z_PGSQL_LINK_P(pgsql_link);
12441247
CHECK_PGSQL_LINK(link);
1248+
} else {
1249+
zend_wrong_parameters_count_error(2, 3);
1250+
RETURN_THROWS();
12451251
}
12461252

12471253
pgsql = link->conn;
@@ -1343,7 +1349,7 @@ PHP_FUNCTION(pg_prepare)
13431349

13441350
link = FETCH_DEFAULT_LINK();
13451351
CHECK_DEFAULT_LINK(link);
1346-
} else {
1352+
} else if (ZEND_NUM_ARGS() == 3) {
13471353
ZEND_PARSE_PARAMETERS_START(3, 3)
13481354
Z_PARAM_OBJECT_OF_CLASS(pgsql_link, pgsql_link_ce)
13491355
Z_PARAM_STRING(stmtname, stmtname_len)
@@ -1352,6 +1358,9 @@ PHP_FUNCTION(pg_prepare)
13521358

13531359
link = Z_PGSQL_LINK_P(pgsql_link);
13541360
CHECK_PGSQL_LINK(link);
1361+
} else {
1362+
zend_wrong_parameters_count_error(2, 3);
1363+
RETURN_THROWS();
13551364
}
13561365

13571366
pgsql = link->conn;
@@ -1429,7 +1438,7 @@ PHP_FUNCTION(pg_execute)
14291438

14301439
link = FETCH_DEFAULT_LINK();
14311440
CHECK_DEFAULT_LINK(link);
1432-
} else {
1441+
} else if (ZEND_NUM_ARGS() == 3) {
14331442
ZEND_PARSE_PARAMETERS_START(3, 3)
14341443
Z_PARAM_OBJECT_OF_CLASS(pgsql_link, pgsql_link_ce)
14351444
Z_PARAM_STRING(stmtname, stmtname_len)
@@ -1438,6 +1447,9 @@ PHP_FUNCTION(pg_execute)
14381447

14391448
link = Z_PGSQL_LINK_P(pgsql_link);
14401449
CHECK_PGSQL_LINK(link);
1450+
} else {
1451+
zend_wrong_parameters_count_error(2, 3);
1452+
RETURN_THROWS();
14411453
}
14421454

14431455
pgsql = link->conn;
@@ -2229,7 +2241,7 @@ static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type, bo
22292241
Z_PARAM_OBJECT_OF_CLASS(result, pgsql_result_ce)
22302242
Z_PARAM_STR_OR_LONG(field_name, field_offset)
22312243
ZEND_PARSE_PARAMETERS_END();
2232-
} else {
2244+
} else if (ZEND_NUM_ARGS() == 3) {
22332245
ZEND_PARSE_PARAMETERS_START(3, 3)
22342246
Z_PARAM_OBJECT_OF_CLASS(result, pgsql_result_ce)
22352247
if (nullable_row) {
@@ -2239,6 +2251,9 @@ static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type, bo
22392251
}
22402252
Z_PARAM_STR_OR_LONG(field_name, field_offset)
22412253
ZEND_PARSE_PARAMETERS_END();
2254+
} else {
2255+
zend_wrong_parameters_count_error(2, 3);
2256+
RETURN_THROWS();
22422257
}
22432258

22442259
pg_result = Z_PGSQL_RESULT_P(result);
@@ -3069,14 +3084,17 @@ PHP_FUNCTION(pg_set_error_verbosity)
30693084

30703085
link = FETCH_DEFAULT_LINK();
30713086
CHECK_DEFAULT_LINK(link);
3072-
} else {
3087+
} else if (ZEND_NUM_ARGS() == 2) {
30733088
ZEND_PARSE_PARAMETERS_START(2, 2)
30743089
Z_PARAM_OBJECT_OF_CLASS(pgsql_link, pgsql_link_ce)
30753090
Z_PARAM_LONG(verbosity)
30763091
ZEND_PARSE_PARAMETERS_END();
30773092

30783093
link = Z_PGSQL_LINK_P(pgsql_link);
30793094
CHECK_PGSQL_LINK(link);
3095+
} else {
3096+
zend_wrong_parameters_count_error(1, 2);
3097+
RETURN_THROWS();
30803098
}
30813099

30823100
pgsql = link->conn;
@@ -3147,14 +3165,17 @@ PHP_FUNCTION(pg_set_client_encoding)
31473165

31483166
link = FETCH_DEFAULT_LINK();
31493167
CHECK_DEFAULT_LINK(link);
3150-
} else {
3168+
} else if (ZEND_NUM_ARGS() == 2) {
31513169
ZEND_PARSE_PARAMETERS_START(2, 2)
31523170
Z_PARAM_OBJECT_OF_CLASS(pgsql_link, pgsql_link_ce)
31533171
Z_PARAM_STRING(encoding, encoding_len)
31543172
ZEND_PARSE_PARAMETERS_END();
31553173

31563174
link = Z_PGSQL_LINK_P(pgsql_link);
31573175
CHECK_PGSQL_LINK(link);
3176+
} else {
3177+
zend_wrong_parameters_count_error(1, 2);
3178+
RETURN_THROWS();
31583179
}
31593180

31603181
pgsql = link->conn;
@@ -3241,14 +3262,17 @@ PHP_FUNCTION(pg_put_line)
32413262

32423263
link = FETCH_DEFAULT_LINK();
32433264
CHECK_DEFAULT_LINK(link);
3244-
} else {
3265+
} else if (ZEND_NUM_ARGS() == 2) {
32453266
ZEND_PARSE_PARAMETERS_START(2, 2)
32463267
Z_PARAM_OBJECT_OF_CLASS(pgsql_link, pgsql_link_ce)
32473268
Z_PARAM_STRING(query, query_len)
32483269
ZEND_PARSE_PARAMETERS_END();
32493270

32503271
link = Z_PGSQL_LINK_P(pgsql_link);
32513272
CHECK_PGSQL_LINK(link);
3273+
} else {
3274+
zend_wrong_parameters_count_error(1, 2);
3275+
RETURN_THROWS();
32523276
}
32533277

32543278
pgsql = link->conn;

ext/pgsql/tests/gh17165.phpt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
--TEST--
2+
Fix pg_query()/pg_query_params()/pg_prepare()/pg_execute()/pg_set_error_verbosity()/pg_set_client_encoding()/pg_put_line() pg field infos calls ArgumentCountError message.
3+
--EXTENSIONS--
4+
pgsql
5+
--SKIPIF--
6+
<?php
7+
include("skipif.inc");
8+
?>
9+
--FILE--
10+
<?php
11+
12+
13+
include "config.inc";
14+
15+
$db = pg_connect($conn_str);
16+
try {
17+
pg_query("a", "b", "c");
18+
} catch (ArgumentCountError $e) {
19+
echo $e->getMessage(), PHP_EOL;
20+
}
21+
22+
try {
23+
pg_query_params($db, "b", array(), "d");
24+
} catch (ArgumentCountError $e) {
25+
echo $e->getMessage(), PHP_EOL;
26+
}
27+
28+
try {
29+
pg_prepare($db, "a", "b", "c");
30+
} catch (ArgumentCountError $e) {
31+
echo $e->getMessage(), PHP_EOL;
32+
}
33+
34+
try {
35+
pg_set_error_verbosity($db, 0, PHP_INT_MAX);
36+
} catch (ArgumentCountError $e) {
37+
echo $e->getMessage(), PHP_EOL;
38+
}
39+
40+
try {
41+
pg_set_client_encoding($db, "foo", "bar");
42+
} catch (ArgumentCountError $e) {
43+
echo $e->getMessage(), PHP_EOL;
44+
}
45+
46+
try {
47+
pg_put_line($db, "my", "data");
48+
} catch (ArgumentCountError $e) {
49+
echo $e->getMessage(), PHP_EOL;
50+
}
51+
52+
try {
53+
pg_field_is_null($db, false, "myfield", new stdClass());
54+
} catch (ArgumentCountError $e) {
55+
echo $e->getMessage(), PHP_EOL;
56+
}
57+
?>
58+
--EXPECT--
59+
pg_query() expects at most 2 arguments, 3 given
60+
pg_query_params() expects at most 3 arguments, 4 given
61+
pg_prepare() expects at most 3 arguments, 4 given
62+
pg_set_error_verbosity() expects at most 2 arguments, 3 given
63+
pg_set_client_encoding() expects at most 2 arguments, 3 given
64+
pg_put_line() expects at most 2 arguments, 3 given
65+
pg_field_is_null() expects at most 3 arguments, 4 given

0 commit comments

Comments
 (0)