@@ -1318,6 +1318,9 @@ static void cls_method_dtor(zval *el) /* {{{ */ {
1318
1318
if (ZEND_MAP_PTR (func -> common .run_time_cache )) {
1319
1319
efree (ZEND_MAP_PTR (func -> common .run_time_cache ));
1320
1320
}
1321
+ if (func -> common .attributes ) {
1322
+ zend_hash_release (func -> common .attributes );
1323
+ }
1321
1324
efree (func );
1322
1325
}
1323
1326
/* }}} */
@@ -1330,10 +1333,39 @@ static void cls_method_pdtor(zval *el) /* {{{ */ {
1330
1333
if (ZEND_MAP_PTR (func -> common .run_time_cache )) {
1331
1334
pefree (ZEND_MAP_PTR (func -> common .run_time_cache ), 1 );
1332
1335
}
1336
+ if (func -> common .attributes ) {
1337
+ zend_hash_release (func -> common .attributes );
1338
+ }
1333
1339
pefree (func , 1 );
1334
1340
}
1335
1341
/* }}} */
1336
1342
1343
+ /* We can not 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
+
1337
1369
/* {{{ overloaded object handlers for PDO class */
1338
1370
bool pdo_hash_methods (pdo_dbh_object_t * dbh_obj , int kind )
1339
1371
{
@@ -1371,6 +1403,7 @@ bool pdo_hash_methods(pdo_dbh_object_t *dbh_obj, int kind)
1371
1403
} else {
1372
1404
func .fn_flags = ZEND_ACC_PUBLIC | ZEND_ACC_NEVER_CACHE ;
1373
1405
}
1406
+ func .fn_flags |= ZEND_ACC_DEPRECATED ;
1374
1407
func .doc_comment = NULL ;
1375
1408
if (funcs -> arg_info ) {
1376
1409
zend_internal_function_info * info = (zend_internal_function_info * )funcs -> arg_info ;
@@ -1399,8 +1432,33 @@ bool pdo_hash_methods(pdo_dbh_object_t *dbh_obj, int kind)
1399
1432
namelen = strlen (funcs -> fname );
1400
1433
lc_name = emalloc (namelen + 1 );
1401
1434
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 ));
1403
1436
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
+ zend_attribute * attr = zend_add_function_attribute (func_p ,
1448
+ ZSTR_KNOWN (ZEND_STR_DEPRECATED_CAPITALIZED ), 2 );
1449
+
1450
+ attr -> args [0 ].name = ZSTR_KNOWN (ZEND_STR_SINCE );
1451
+ ZVAL_STR (& attr -> args [0 ].value , ZSTR_KNOWN (ZEND_STR_8_DOT_5 ));
1452
+
1453
+ char * message ;
1454
+ size_t len = zend_spprintf (& message , 0 , "use %s() instead" , new_name );
1455
+ zend_string * message_str = zend_string_init_interned (message , len , true);
1456
+ efree (message );
1457
+
1458
+ attr -> args [1 ].name = ZSTR_KNOWN (ZEND_STR_MESSAGE );
1459
+ ZVAL_STR (& attr -> args [1 ].value , message_str );
1460
+ }
1461
+
1404
1462
funcs ++ ;
1405
1463
}
1406
1464
0 commit comments