From de74ca82e4930567decd71148e193a7e5f247d12 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Wed, 9 Oct 2024 14:20:56 -0700 Subject: [PATCH] GH-16317: make `__debugInfo()` overrides work --- ext/standard/var.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ext/standard/var.c b/ext/standard/var.c index 1c2b0eb164a1c..ff09b3546f566 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -175,7 +175,16 @@ PHPAPI void php_var_dump(zval *struc, int level) /* {{{ */ } ZEND_GUARD_OR_GC_PROTECT_RECURSION(guard, DEBUG, zobj); - myht = zend_get_properties_for(struc, ZEND_PROP_PURPOSE_DEBUG); + // GH-16317: for user classes with __debugInfo() always call that + if (ce->type == ZEND_USER_CLASS && ce->__debugInfo != NULL) { + int is_temp; + myht = (std_object_handlers.get_debug_info)(zobj, &is_temp); + if (myht && !is_temp) { + GC_TRY_ADDREF(myht); + } + } else { + myht = zend_get_properties_for(struc, ZEND_PROP_PURPOSE_DEBUG); + } class_name = Z_OBJ_HANDLER_P(struc, get_class_name)(Z_OBJ_P(struc)); const char *prefix = php_var_dump_object_prefix(Z_OBJ_P(struc));