From 2f4dd5ca35ffcf7642b2428102455ef648f9f039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 17 Oct 2025 12:48:42 +0200 Subject: [PATCH] pdo: Fix scope for PDO mixins in pdo_hash_methods() From what I see the incorrect scope is not observable in any other way. The mixin methods are completely invisible to Reflection and a SQLite function referring to a private method is still properly called as before. Fixes php/php-src#20095. --- NEWS | 4 ++++ ext/pdo/pdo_dbh.c | 2 +- ext/pdo_sqlite/tests/gh20095.phpt | 25 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 ext/pdo_sqlite/tests/gh20095.phpt diff --git a/NEWS b/NEWS index 353df7d7a8921..dab1c1158ae26 100644 --- a/NEWS +++ b/NEWS @@ -26,6 +26,10 @@ PHP NEWS . Fixed bug GH-19994 (openssl_get_cipher_methods inconsistent with fetching). (Jakub Zelenka) +- PDO: + . Fixed bug GH-20095 (Incorrect class name in deprecation message for PDO + mixins). (timwolla) + - Phar: . Fix potential buffer length truncation due to usage of type int instead of type size_t. (Girgias) diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 1bdfcd935cfd1..08e398ea3682e 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -1394,7 +1394,7 @@ bool pdo_hash_methods(pdo_dbh_object_t *dbh_obj, int kind) func.type = ZEND_INTERNAL_FUNCTION; func.handler = funcs->handler; func.function_name = zend_string_init(funcs->fname, strlen(funcs->fname), dbh->is_persistent); - func.scope = dbh_obj->std.ce; + func.scope = pdo_dbh_ce; func.prototype = NULL; ZEND_MAP_PTR(func.run_time_cache) = rt_cache_size ? pecalloc(rt_cache_size, 1, dbh->is_persistent) : NULL; func.T = ZEND_OBSERVER_ENABLED; diff --git a/ext/pdo_sqlite/tests/gh20095.phpt b/ext/pdo_sqlite/tests/gh20095.phpt new file mode 100644 index 0000000000000..8d691f99ee2aa --- /dev/null +++ b/ext/pdo_sqlite/tests/gh20095.phpt @@ -0,0 +1,25 @@ +--TEST-- +GH-20095: Incorrect class name in deprecation message for PDO mixins +--EXTENSIONS-- +pdo_sqlite +--FILE-- +sqliteCreateFunction('my_test', [$this, "test"]); + } +} + +$pdo = new Foo('sqlite::memory:'); +$pdo->register(); +$pdo->query("SELECT my_test()"); + +?> +--EXPECTF-- +Deprecated: Method PDO::sqliteCreateFunction() is deprecated since 8.5, use Pdo\Sqlite::createFunction() instead in %s on line %d +foo