Skip to content

Commit a206b88

Browse files
GH-16317: allow __debugInfo() overrides in mysqli classes
For classes that extend `mysqli`, `mysqli_result`, or `mysqli_statement`, and define a `__debugInfo()` magic method, use it.
1 parent 6dd67bb commit a206b88

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

ext/mysqli/mysqli.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ static int mysqli_object_has_property(zend_object *object, zend_string *name, in
342342

343343
HashTable *mysqli_object_get_debug_info(zend_object *object, int *is_temp)
344344
{
345+
/* GH-16317: allow subclasses to use __debugInfo() */
346+
if (object->ce->__debugInfo != NULL) {
347+
return zend_std_get_debug_info(object, is_temp);
348+
}
345349
mysqli_object *obj = php_mysqli_fetch_object(object);
346350
HashTable *retval, *props = obj->prop_handler;
347351
mysqli_prop_handler *entry;

ext/mysqli/tests/gh16317.phpt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
--TEST--
2+
GH-16317 (__debugInfo() overrides don't work)
3+
--EXTENSIONS--
4+
mysqli
5+
--FILE--
6+
<?php
7+
8+
class subclass_mysqli extends mysqli {
9+
public function __construct() {}
10+
public function __debugInfo(): array {
11+
return ['a' => 'b'];
12+
}
13+
}
14+
var_dump( new subclass_mysqli() );
15+
16+
class subclass_mysqli_result extends mysqli_result {
17+
public function __construct() {}
18+
public function __debugInfo(): array {
19+
return ['o' => 'p'];
20+
}
21+
}
22+
var_dump( new subclass_mysqli_result() );
23+
24+
class subclass_mysqli_stmt extends mysqli_stmt {
25+
public function __construct() {}
26+
public function __debugInfo(): array {
27+
return ['x' => 'y'];
28+
}
29+
}
30+
var_dump( new subclass_mysqli_stmt() );
31+
32+
?>
33+
--EXPECT--
34+
object(subclass_mysqli)#1 (1) {
35+
["a"]=>
36+
string(1) "b"
37+
}
38+
object(subclass_mysqli_result)#1 (1) {
39+
["o"]=>
40+
string(1) "p"
41+
}
42+
object(subclass_mysqli_stmt)#1 (1) {
43+
["x"]=>
44+
string(1) "y"
45+
}

0 commit comments

Comments
 (0)