Skip to content

Commit 1cb166c

Browse files
authored
pdo: Fix scope for PDO mixins in pdo_hash_methods() (php#20200)
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#20095.
1 parent 9282111 commit 1cb166c

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ PHP NEWS
2626
. Fixed bug GH-19994 (openssl_get_cipher_methods inconsistent with fetching).
2727
(Jakub Zelenka)
2828

29+
- PDO:
30+
. Fixed bug GH-20095 (Incorrect class name in deprecation message for PDO
31+
mixins). (timwolla)
32+
2933
- Phar:
3034
. Fix potential buffer length truncation due to usage of type int instead
3135
of type size_t. (Girgias)

ext/pdo/pdo_dbh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ bool pdo_hash_methods(pdo_dbh_object_t *dbh_obj, int kind)
13941394
func.type = ZEND_INTERNAL_FUNCTION;
13951395
func.handler = funcs->handler;
13961396
func.function_name = zend_string_init(funcs->fname, strlen(funcs->fname), dbh->is_persistent);
1397-
func.scope = dbh_obj->std.ce;
1397+
func.scope = pdo_dbh_ce;
13981398
func.prototype = NULL;
13991399
ZEND_MAP_PTR(func.run_time_cache) = rt_cache_size ? pecalloc(rt_cache_size, 1, dbh->is_persistent) : NULL;
14001400
func.T = ZEND_OBSERVER_ENABLED;

ext/pdo_sqlite/tests/gh20095.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
GH-20095: Incorrect class name in deprecation message for PDO mixins
3+
--EXTENSIONS--
4+
pdo_sqlite
5+
--FILE--
6+
<?php
7+
8+
class Foo extends PDO {
9+
private function test() {
10+
echo "foo";
11+
}
12+
13+
public function register() {
14+
$this->sqliteCreateFunction('my_test', [$this, "test"]);
15+
}
16+
}
17+
18+
$pdo = new Foo('sqlite::memory:');
19+
$pdo->register();
20+
$pdo->query("SELECT my_test()");
21+
22+
?>
23+
--EXPECTF--
24+
Deprecated: Method PDO::sqliteCreateFunction() is deprecated since 8.5, use Pdo\Sqlite::createFunction() instead in %s on line %d
25+
foo

0 commit comments

Comments
 (0)