@@ -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 */
13381370bool 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
0 commit comments