Skip to content

Commit beaf1e8

Browse files
committed
Deprecate calling pg_fetch_result(), pg_field_prtlen(), and pg_field_is_null() with 2 arguments
1 parent 682c236 commit beaf1e8

11 files changed

+54
-20
lines changed

UPGRADING

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ PHP 8.4 UPGRADE NOTES
161161
. Calling ldap_exop() with more than 4 arguments is deprecated. Use
162162
ldap_exop_sync() instead.
163163

164+
- PgSQL:
165+
. Calling pgsql_fetch_result() with 2 arguments is deprecated. Use the
166+
3-parameter signature with a null $row parameter instead.
167+
. Calling pg_field_prtlen() with 2 arguments is deprecated. Use the
168+
3-parameter signature with a null $row parameter instead.
169+
. Calling pg_field_is_null() with 2 arguments is deprecated. Use the
170+
3-parameter signature with a null $row parameter instead.
171+
164172
========================================
165173
5. Changed Functions
166174
========================================

ext/pgsql/pgsql.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,14 @@ PHP_FUNCTION(pg_fetch_result)
16981698
int pgsql_row;
16991699

17001700
if (ZEND_NUM_ARGS() == 2) {
1701+
if (zend_string_equals_literal(EX(func)->common.function_name, "pg_fetch_result")) {
1702+
zend_error(E_DEPRECATED, "Calling pg_fetch_result() with 2 arguments is deprecated, "
1703+
"use the 3-parameter signature with a null $row parameter instead");
1704+
if (UNEXPECTED(EG(exception))) {
1705+
RETURN_THROWS();
1706+
}
1707+
}
1708+
17011709
ZEND_PARSE_PARAMETERS_START(2, 2)
17021710
Z_PARAM_OBJECT_OF_CLASS(result, pgsql_result_ce)
17031711
Z_PARAM_STR_OR_LONG(field_name, field_offset)
@@ -2009,6 +2017,15 @@ static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type, bo
20092017
int pgsql_row;
20102018

20112019
if (ZEND_NUM_ARGS() == 2) {
2020+
if (nullable_row) {
2021+
zend_error(E_DEPRECATED, "Calling %s() with 2 arguments is deprecated, "
2022+
"use the 3-parameter signature with a null $row parameter instead",
2023+
ZSTR_VAL(EX(func)->common.function_name));
2024+
if (UNEXPECTED(EG(exception))) {
2025+
RETURN_THROWS();
2026+
}
2027+
}
2028+
20122029
ZEND_PARSE_PARAMETERS_START(2, 2)
20132030
Z_PARAM_OBJECT_OF_CLASS(result, pgsql_result_ce)
20142031
Z_PARAM_STR_OR_LONG(field_name, field_offset)

ext/pgsql/tests/03sync_query.phpt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,21 @@ pg_field_name($result, 0);
8989
pg_field_num($result, "num");
9090
pg_field_size($result, 0);
9191
pg_field_type($result, 0);
92-
pg_field_prtlen($result, 0);
93-
pg_field_is_null($result, 0);
92+
pg_field_prtlen($result, null, 0);
93+
pg_field_is_null($result, null, 0);
9494

9595
try {
96-
pg_field_is_null($result, -1);
96+
pg_field_is_null($result, null, -1);
9797
} catch (ValueError $e) {
9898
echo $e->getMessage(), "\n";
9999
}
100100
try {
101-
pg_field_is_null($result, 3);
101+
pg_field_is_null($result, null, 3);
102102
} catch (ValueError $e) {
103103
echo $e->getMessage(), "\n";
104104
}
105105
try {
106-
pg_field_is_null($result, "unknown");
106+
pg_field_is_null($result, null, "unknown");
107107
} catch (ValueError $e) {
108108
echo $e->getMessage(), "\n";
109109
}
@@ -151,9 +151,9 @@ Argument #3 must be less than the number of fields for this result set
151151
Argument #3 must be a field name from this result set
152152
pg_fetch_all_columns(): Argument #2 ($field) must be greater than or equal to 0
153153
pg_fetch_all_columns(): Argument #2 ($field) must be less than the number of fields for this result set
154-
Argument #2 must be greater than or equal to 0
155-
Argument #2 must be less than the number of fields for this result set
156-
Argument #2 must be a field name from this result set
154+
Argument #3 must be greater than or equal to 0
155+
Argument #3 must be less than the number of fields for this result set
156+
Argument #3 must be a field name from this result set
157157
pg_field_name(): Argument #2 ($field) must be greater than or equal to 0
158158
pg_field_name(): Argument #2 ($field) must be less than the number of fields for this result set
159159
pg_field_table(): Argument #2 ($field) must be greater than or equal to 0

ext/pgsql/tests/04async_query.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,8 @@ $table_name = "table_04async_query";
7474
$db = pg_connect($conn_str);
7575
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
7676
?>
77-
--EXPECT--
77+
--EXPECTF--
78+
Deprecated: Calling pg_field_prtlen() with 2 arguments is deprecated, use the 3-parameter signature with a null $row parameter instead in %s on line %d
79+
80+
Deprecated: Calling pg_field_is_null() with 2 arguments is deprecated, use the 3-parameter signature with a null $row parameter instead in %s on line %d
7881
OK

ext/pgsql/tests/24sync_query_prepared.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ pg_field_name($result, 0);
4949
pg_field_num($result, "num");
5050
pg_field_size($result, 0);
5151
pg_field_type($result, 0);
52-
pg_field_prtlen($result, 0);
53-
pg_field_is_null($result, 0);
52+
pg_field_prtlen($result, null, 0);
53+
pg_field_is_null($result, null, 0);
5454

5555
$result = pg_prepare($db, "php_test2", "INSERT INTO ".$table_name." VALUES (\$1, \$2);");
5656
pg_result_error($result);

ext/pgsql/tests/25async_query_params.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ pg_field_name($result, 0);
5454
pg_field_num($result, "num");
5555
pg_field_size($result, 0);
5656
pg_field_type($result, 0);
57-
pg_field_prtlen($result, 0);
58-
pg_field_is_null($result, 0);
57+
pg_field_prtlen($result, null, 0);
58+
pg_field_is_null($result, null, 0);
5959

6060
if (!pg_send_query_params($db, "INSERT INTO ".$table_name." VALUES (\$1, \$2);", array(9999, "A'BC")))
6161
{

ext/pgsql/tests/26async_query_prepared.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ pg_field_name($result, 0);
6868
pg_field_num($result, "num");
6969
pg_field_size($result, 0);
7070
pg_field_type($result, 0);
71-
pg_field_prtlen($result, 0);
72-
pg_field_is_null($result, 0);
71+
pg_field_prtlen($result, null, 0);
72+
pg_field_is_null($result, null, 0);
7373

7474
if (!pg_send_prepare($db, "php_test2", "INSERT INTO ".$table_name." VALUES (\$1, \$2);"))
7575
{

ext/pgsql/tests/30nb_async_query_params.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ pg_field_name($result, 0);
5555
pg_field_num($result, "num");
5656
pg_field_size($result, 0);
5757
pg_field_type($result, 0);
58-
pg_field_prtlen($result, 0);
59-
pg_field_is_null($result, 0);
58+
pg_field_prtlen($result, null, 0);
59+
pg_field_is_null($result, null, 0);
6060

6161
$sent = pg_send_query_params($db, "INSERT INTO ".$table_name." VALUES (\$1, \$2);", array(9999, "A'BC"));
6262

ext/pgsql/tests/31nb_async_query_prepared.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,8 @@ $table_name = "table_31nb_async_query_prepared";
114114
$db = pg_connect($conn_str);
115115
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
116116
?>
117-
--EXPECT--
117+
--EXPECTF--
118+
Deprecated: Calling pg_field_prtlen() with 2 arguments is deprecated, use the 3-parameter signature with a null $row parameter instead in %s on line %d
119+
120+
Deprecated: Calling pg_field_is_null() with 2 arguments is deprecated, use the 3-parameter signature with a null $row parameter instead in %s on line %d
118121
OK

ext/pgsql/tests/bug37100.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ $table_name = 'table_bug37100';
4343
$db = pg_connect($conn_str);
4444
pg_query("DROP TABLE IF EXISTS {$table_name}");
4545
?>
46-
--EXPECT--
46+
--EXPECTF--
47+
Deprecated: Calling pg_fetch_result() with 2 arguments is deprecated, use the 3-parameter signature with a null $row parameter instead in %s on line %d
4748
string(24) "\001\003\252\000\010\022"
4849
string(12) "0103aa000812"
50+
51+
Deprecated: Calling pg_fetch_result() with 2 arguments is deprecated, use the 3-parameter signature with a null $row parameter instead in %s on line %d
4952
int(6)
5053
string(12) "0103aa000812"

ext/pgsql/tests/bug76548.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ $conn = pg_connect($conn_str);
1212

1313
$result = pg_query($conn, 'SELECT v FROM (VALUES (1), (2), (3)) AS t(v)');
1414

15-
while ($value = pg_fetch_result($result, 0)) {
15+
while ($value = pg_fetch_result($result, null, 0)) {
1616
var_dump($value); // should be 1, 2 then 3.
1717
}
1818

0 commit comments

Comments
 (0)