Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a4afc57

Browse files
Deprecate driver specific PDO methods
RFC: https://wiki.php.net/rfc/deprecations_php_8_5. Closes GH-19596
1 parent d85662d commit a4afc57

23 files changed

+234
-16
lines changed

‎NEWS‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ PHP NEWS
1919
- PCRE:
2020
. Upgraded to pcre2lib from 10.45 to 10.46. (nielsdos)
2121

22+
- PDO:
23+
. Driver specific methods in the PDO class are now deprecated. (Arnaud)
24+
2225
- Session:
2326
. Fix RC violation of session SID constant deprecation attribute. (ilutov)
2427

‎UPGRADING‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,21 @@ PHP 8.5 UPGRADE NOTES
476476
PDO::SQLITE_OPEN_READWRITE => Pdo\Sqlite::OPEN_READWRITE
477477
PDO::SQLITE_OPEN_CREATE => Pdo\Sqlite::OPEN_CREATE
478478
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_driver_specific_pdo_constants_and_methods
479+
. Driver specific methods in the PDO class have been deprecated.
480+
List of affected methods and their replacement:
481+
PDO::pgsqlCopyFromArray() => Pdo\Pgsql::copyFromArray()
482+
PDO::pgsqlCopyFromFile() => Pdo\Pgsql::copyFromFile()
483+
PDO::pgsqlCopyToArray() => Pdo\Pgsql::copyToArray()
484+
PDO::pgsqlCopyToFile() => Pdo\Pgsql::copyToFile()
485+
PDO::pgsqlGetNotify() => Pdo\Pgsql::getNotify()
486+
PDO::pgsqlGetPid() => Pdo\Pgsql::getPid()
487+
PDO::pgsqlLOBCreate() => Pdo\Pgsql::lobCreate()
488+
PDO::pgsqlLOBOpen() => Pdo\Pgsql::lobOpen()
489+
PDO::pgsqlLOBUnlink() => Pdo\Pgsql::lobUnlink()
490+
PDO::sqliteCreateAggregate() => Pdo\Sqlite::createAggregate()
491+
PDO::sqliteCreateCollation() => Pdo\Sqlite::createCollation()
492+
PDO::sqliteCreateFunction() => Pdo\Sqlite::createFunction()
493+
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_driver_specific_pdo_constants_and_methods
479494

480495
- Reflection:
481496
. The setAccessible() methods of various Reflection objects have been

‎ext/pdo/pdo_dbh.c‎

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,9 @@ static void cls_method_dtor(zval *el) /* {{{ */ {
13181318
if (ZEND_MAP_PTR(func->common.run_time_cache)) {
13191319
efree(ZEND_MAP_PTR(func->common.run_time_cache));
13201320
}
1321+
if (func->common.attributes) {
1322+
zend_hash_release(func->common.attributes);
1323+
}
13211324
efree(func);
13221325
}
13231326
/* }}} */
@@ -1330,10 +1333,39 @@ static void cls_method_pdtor(zval *el) /* {{{ */ {
13301333
if (ZEND_MAP_PTR(func->common.run_time_cache)) {
13311334
pefree(ZEND_MAP_PTR(func->common.run_time_cache), 1);
13321335
}
1336+
if (func->common.attributes) {
1337+
zend_hash_release(func->common.attributes);
1338+
}
13331339
pefree(func, 1);
13341340
}
13351341
/* }}} */
13361342

1343+
/* We cannot add #[Deprecated] attributes in @generate-function-entries stubs,
1344+
* and PDO drivers have no way to add them either, so we hard-code deprecation
1345+
* info here and add the attribute manually in pdo_hash_methods() */
1346+
struct driver_specific_method_deprecation {
1347+
const char *old_name;
1348+
const char *new_name;
1349+
};
1350+
1351+
/* Methods deprecated in https://wiki.php.net/rfc/deprecations_php_8_5
1352+
* "Deprecate driver specific PDO constants and methods" */
1353+
static const struct driver_specific_method_deprecation driver_specific_method_deprecations[] = {
1354+
{"pgsqlCopyFromArray", "Pdo\\Pgsql::copyFromArray"},
1355+
{"pgsqlCopyFromFile", "Pdo\\Pgsql::copyFromFile"},
1356+
{"pgsqlCopyToArray", "Pdo\\Pgsql::copyToArray"},
1357+
{"pgsqlCopyToFile", "Pdo\\Pgsql::copyToFile"},
1358+
{"pgsqlGetNotify", "Pdo\\Pgsql::getNotify"},
1359+
{"pgsqlGetPid", "Pdo\\Pgsql::getPid"},
1360+
{"pgsqlLOBCreate", "Pdo\\Pgsql::lobCreate"},
1361+
{"pgsqlLOBOpen", "Pdo\\Pgsql::lobOpen"},
1362+
{"pgsqlLOBUnlink", "Pdo\\Pgsql::lobUnlink"},
1363+
{"sqliteCreateAggregate", "Pdo\\Sqlite::createAggregate"},
1364+
{"sqliteCreateCollation", "Pdo\\Sqlite::createCollation"},
1365+
{"sqliteCreateFunction", "Pdo\\Sqlite::createFunction"},
1366+
{NULL, NULL},
1367+
};
1368+
13371369
/* {{{ overloaded object handlers for PDO class */
13381370
bool pdo_hash_methods(pdo_dbh_object_t *dbh_obj, int kind)
13391371
{
@@ -1371,6 +1403,7 @@ bool pdo_hash_methods(pdo_dbh_object_t *dbh_obj, int kind)
13711403
} else {
13721404
func.fn_flags = ZEND_ACC_PUBLIC | ZEND_ACC_NEVER_CACHE;
13731405
}
1406+
func.fn_flags |= ZEND_ACC_DEPRECATED;
13741407
func.doc_comment = NULL;
13751408
if (funcs->arg_info) {
13761409
zend_internal_function_info *info = (zend_internal_function_info*)funcs->arg_info;
@@ -1399,8 +1432,36 @@ bool pdo_hash_methods(pdo_dbh_object_t *dbh_obj, int kind)
13991432
namelen = strlen(funcs->fname);
14001433
lc_name = emalloc(namelen+1);
14011434
zend_str_tolower_copy(lc_name, funcs->fname, namelen);
1402-
zend_hash_str_add_mem(dbh->cls_methods[kind], lc_name, namelen, &func, sizeof(func));
1435+
zend_function*func_p=zend_hash_str_add_mem(dbh->cls_methods[kind], lc_name, namelen, &func, sizeof(func));
14031436
efree(lc_name);
1437+
1438+
const char *new_name = NULL;
1439+
for (const struct driver_specific_method_deprecation *d = driver_specific_method_deprecations;
1440+
d->old_name; d++) {
1441+
if (strcmp(d->old_name, funcs->fname) == 0) {
1442+
new_name = d->new_name;
1443+
break;
1444+
}
1445+
}
1446+
if (new_name) {
1447+
uint32_t flags = dbh->is_persistent ? ZEND_ATTRIBUTE_PERSISTENT : 0;
1448+
zend_attribute *attr = zend_add_attribute(
1449+
&func_p->common.attributes,
1450+
ZSTR_KNOWN(ZEND_STR_DEPRECATED_CAPITALIZED),
1451+
2, flags, 0, 0);
1452+
1453+
attr->args[0].name = ZSTR_KNOWN(ZEND_STR_SINCE);
1454+
ZVAL_STR(&attr->args[0].value, ZSTR_KNOWN(ZEND_STR_8_DOT_5));
1455+
1456+
char *message;
1457+
size_t len = zend_spprintf(&message, 0, "use %s() instead", new_name);
1458+
zend_string *message_str = zend_string_init(message, len, dbh->is_persistent);
1459+
efree(message);
1460+
1461+
attr->args[1].name = ZSTR_KNOWN(ZEND_STR_MESSAGE);
1462+
ZVAL_STR(&attr->args[1].value, message_str);
1463+
}
1464+
14041465
funcs++;
14051466
}
14061467

‎ext/pdo_pgsql/tests/bug68199.phpt‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,31 +80,48 @@ var_dump($notify[2]);
8080
var_dump($db->pgsqlGetNotify());
8181

8282
?>
83-
--EXPECT--
83+
--EXPECTF--
84+
Deprecated: Method PDO::pgsqlGetPid() is deprecated since 8.5, use Pdo\Pgsql::getPid() instead in %s on line %d
8485
bool(true)
86+
87+
Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
8588
bool(false)
89+
90+
Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
8691
bool(false)
92+
93+
Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
8794
int(3)
8895
string(16) "channel_bug68199"
8996
bool(true)
9097
string(7) "payload"
98+
99+
Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
91100
int(3)
92101
string(16) "channel_bug68199"
93102
bool(true)
94103
string(7) "payload"
104+
105+
Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
95106
int(3)
96107
string(16) "channel_bug68199"
97108
bool(true)
98109
string(7) "payload"
110+
111+
Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
99112
int(3)
100113
string(16) "channel_bug68199"
101114
bool(true)
102115
string(7) "payload"
116+
117+
Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
103118
int(6)
104119
string(16) "channel_bug68199"
105120
bool(true)
106121
string(7) "payload"
107122
string(16) "channel_bug68199"
108123
bool(true)
109124
string(7) "payload"
125+
126+
Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
110127
bool(false)

‎ext/pdo_pgsql/tests/copy_from.phpt‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ $db->query('DROP TABLE IF EXISTS test_copy_from CASCADE');
134134
--EXPECTF--
135135
Preparing test file and array for CopyFrom tests
136136
Testing pgsqlCopyFromArray() with default parameters
137+
138+
Deprecated: Method PDO::pgsqlCopyFromArray() is deprecated since 8.5, use Pdo\Pgsql::copyFromArray() instead in %s on line %d
137139
bool(true)
138140
array(6) {
139141
["a"]=>
@@ -178,6 +180,8 @@ array(6) {
178180
NULL
179181
}
180182
Testing pgsqlCopyFromArray() with different field separator and not null indicator
183+
184+
Deprecated: Method PDO::pgsqlCopyFromArray() is deprecated since 8.5, use Pdo\Pgsql::copyFromArray() instead in %s on line %d
181185
bool(true)
182186
array(6) {
183187
["a"]=>
@@ -222,6 +226,8 @@ array(6) {
222226
NULL
223227
}
224228
Testing pgsqlCopyFromArray() with only selected fields
229+
230+
Deprecated: Method PDO::pgsqlCopyFromArray() is deprecated since 8.5, use Pdo\Pgsql::copyFromArray() instead in %s on line %d
225231
bool(true)
226232
array(6) {
227233
["a"]=>
@@ -266,8 +272,12 @@ array(6) {
266272
NULL
267273
}
268274
Testing pgsqlCopyFromArray() with error
275+
276+
Deprecated: Method PDO::pgsqlCopyFromArray() is deprecated since 8.5, use Pdo\Pgsql::copyFromArray() instead in %s on line %d
269277
Exception: SQLSTATE[42P01]: Undefined table: 7 %s: %stest_error%s
270278
Testing pgsqlCopyFromFile() with default parameters
279+
280+
Deprecated: Method PDO::pgsqlCopyFromFile() is deprecated since 8.5, use Pdo\Pgsql::copyFromFile() instead in %s on line %d
271281
bool(true)
272282
array(6) {
273283
["a"]=>
@@ -312,6 +322,8 @@ array(6) {
312322
NULL
313323
}
314324
Testing pgsqlCopyFromFile() with different field separator and not null indicator
325+
326+
Deprecated: Method PDO::pgsqlCopyFromFile() is deprecated since 8.5, use Pdo\Pgsql::copyFromFile() instead in %s on line %d
315327
bool(true)
316328
array(6) {
317329
["a"]=>
@@ -356,6 +368,8 @@ array(6) {
356368
NULL
357369
}
358370
Testing pgsqlCopyFromFile() with only selected fields
371+
372+
Deprecated: Method PDO::pgsqlCopyFromFile() is deprecated since 8.5, use Pdo\Pgsql::copyFromFile() instead in %s on line %d
359373
bool(true)
360374
array(6) {
361375
["a"]=>
@@ -400,6 +414,10 @@ array(6) {
400414
NULL
401415
}
402416
Testing pgsqlCopyFromFile() with error
417+
418+
Deprecated: Method PDO::pgsqlCopyFromFile() is deprecated since 8.5, use Pdo\Pgsql::copyFromFile() instead in %s on line %d
403419
Exception: SQLSTATE[42P01]: Undefined table: 7 %s: %stest_error%s
404420
Testing pgsqlCopyFromFile() with non existing file
421+
422+
Deprecated: Method PDO::pgsqlCopyFromFile() is deprecated since 8.5, use Pdo\Pgsql::copyFromFile() instead in %s on line %d
405423
Exception: SQLSTATE[HY000]: General error: 7 Unable to open the file

‎ext/pdo_pgsql/tests/copy_from_generator.phpt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
4141
$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
4242
$db->query('DROP TABLE IF EXISTS test_copy_from_generator CASCADE');
4343
?>
44-
--EXPECT--
44+
--EXPECTF--
45+
Deprecated: Method PDO::pgsqlCopyFromArray() is deprecated since 8.5, use Pdo\Pgsql::copyFromArray() instead in %s on line %d
4546
array (
4647
0 => 1,
4748
1 => 1,

‎ext/pdo_pgsql/tests/copy_from_iterator.phpt‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,11 @@ require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
6161
$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
6262
$db->query('DROP TABLE IF EXISTS test_copy_from_traversable CASCADE');
6363
?>
64-
--EXPECT--
64+
--EXPECTF--
65+
Deprecated: Method PDO::pgsqlCopyFromArray() is deprecated since 8.5, use Pdo\Pgsql::copyFromArray() instead in %s on line %d
6566
PDO::pgsqlCopyFromArray(): Argument #2 ($rows) must be of type Traversable|array, stdClass given
67+
68+
Deprecated: Method PDO::pgsqlCopyFromArray() is deprecated since 8.5, use Pdo\Pgsql::copyFromArray() instead in %s on line %d
6669
array (
6770
0 => 1,
6871
1 => 1,

‎ext/pdo_pgsql/tests/copy_to.phpt‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ $db->exec('DROP TABLE test_copy_to');
8787
--EXPECTF--
8888
Preparing test table for CopyTo tests
8989
Testing pgsqlCopyToArray() with default parameters
90+
91+
Deprecated: Method PDO::pgsqlCopyToArray() is deprecated since 8.5, use Pdo\Pgsql::copyToArray() instead in %s on line %d
9092
array(3) {
9193
[0]=>
9294
string(19) "0 test insert 0 \N
@@ -99,6 +101,8 @@ array(3) {
99101
"
100102
}
101103
Testing pgsqlCopyToArray() with different field separator and not null indicator
104+
105+
Deprecated: Method PDO::pgsqlCopyToArray() is deprecated since 8.5, use Pdo\Pgsql::copyToArray() instead in %s on line %d
102106
array(3) {
103107
[0]=>
104108
string(21) "0;test insert 0;NULL
@@ -111,6 +115,8 @@ array(3) {
111115
"
112116
}
113117
Testing pgsqlCopyToArray() with only selected fields
118+
119+
Deprecated: Method PDO::pgsqlCopyToArray() is deprecated since 8.5, use Pdo\Pgsql::copyToArray() instead in %s on line %d
114120
array(3) {
115121
[0]=>
116122
string(7) "0;NULL
@@ -123,23 +129,35 @@ array(3) {
123129
"
124130
}
125131
Testing pgsqlCopyToArray() with error
132+
133+
Deprecated: Method PDO::pgsqlCopyToArray() is deprecated since 8.5, use Pdo\Pgsql::copyToArray() instead in %s on line %d
126134
Exception: SQLSTATE[42P01]: Undefined table: 7 %s: %stest_error%s
127135
Testing pgsqlCopyToFile() with default parameters
136+
137+
Deprecated: Method PDO::pgsqlCopyToFile() is deprecated since 8.5, use Pdo\Pgsql::copyToFile() instead in %s on line %d
128138
bool(true)
129139
0 test insert 0 \N
130140
1 test insert 1 \N
131141
2 test insert 2 \N
132142
Testing pgsqlCopyToFile() with different field separator and not null indicator
143+
144+
Deprecated: Method PDO::pgsqlCopyToFile() is deprecated since 8.5, use Pdo\Pgsql::copyToFile() instead in %s on line %d
133145
bool(true)
134146
0;test insert 0;NULL
135147
1;test insert 1;NULL
136148
2;test insert 2;NULL
137149
Testing pgsqlCopyToFile() with only selected fields
150+
151+
Deprecated: Method PDO::pgsqlCopyToFile() is deprecated since 8.5, use Pdo\Pgsql::copyToFile() instead in %s on line %d
138152
bool(true)
139153
0;NULL
140154
1;NULL
141155
2;NULL
142156
Testing pgsqlCopyToFile() with error
157+
158+
Deprecated: Method PDO::pgsqlCopyToFile() is deprecated since 8.5, use Pdo\Pgsql::copyToFile() instead in %s on line %d
143159
Exception: SQLSTATE[42P01]: Undefined table: 7 %s: %stest_error%s
144160
Testing pgsqlCopyToFile() to unwritable file
161+
162+
Deprecated: Method PDO::pgsqlCopyToFile() is deprecated since 8.5, use Pdo\Pgsql::copyToFile() instead in %s on line %d
145163
Exception: SQLSTATE[HY000]: General error: 7 Unable to open the file for writing

‎ext/pdo_pgsql/tests/getnotify.phpt‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,29 +84,50 @@ var_dump($diff < 1 || abs(1 - abs($diff)) < .05);
8484
var_dump(count($notify));
8585

8686
?>
87-
--EXPECT--
87+
--EXPECTF--
88+
Deprecated: Method PDO::pgsqlGetPid() is deprecated since 8.5, use Pdo\Pgsql::getPid() instead in %s on line %d
8889
bool(true)
90+
91+
Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
8992
bool(false)
93+
94+
Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
9095
bool(false)
96+
97+
Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
9198
int(2)
9299
string(17) "channel_getnotify"
93100
bool(true)
101+
102+
Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
94103
int(2)
95104
string(17) "channel_getnotify"
96105
bool(true)
106+
107+
Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
97108
int(2)
98109
string(17) "channel_getnotify"
99110
bool(true)
111+
112+
Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
100113
int(2)
101114
string(17) "channel_getnotify"
102115
bool(true)
116+
117+
Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
103118
int(4)
104119
string(17) "channel_getnotify"
105120
bool(true)
106121
string(17) "channel_getnotify"
107122
bool(true)
123+
124+
Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
108125
bool(false)
126+
127+
Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
109128
bool(true)
110129
bool(false)
130+
131+
Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
111132
bool(true)
112133
int(2)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /