Skip to content

Commit 55e4a6b

Browse files
committed
Merge branch 'xdebug_3_4'
* xdebug_3_4: Fixed issue #2375: Xdebug's exception trace conversion initialises lazy objects
2 parents cf596ec + 507f0d8 commit 55e4a6b

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

src/lib/var_export_line.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
+----------------------------------------------------------------------+
33
| Xdebug |
44
+----------------------------------------------------------------------+
5-
| Copyright (c) 2002-2024 Derick Rethans |
5+
| Copyright (c) 2002-2025 Derick Rethans |
66
+----------------------------------------------------------------------+
77
| This source file is subject to version 1.01 of the Xdebug license, |
88
| that is bundled with this package in the file LICENSE, and is |
@@ -244,6 +244,23 @@ void xdebug_var_export_line(zval **struc, xdebug_str *str, int level, int debug_
244244
case IS_OBJECT: {
245245
#if PHP_VERSION_ID >= 80100
246246
zend_class_entry *ce = Z_OBJCE_P(*struc);
247+
#endif
248+
249+
#if PHP_VERSION_ID >= 80400
250+
if (
251+
ce->type != ZEND_INTERNAL_CLASS &&
252+
zend_object_is_lazy(Z_OBJ_P(*struc)) &&
253+
!zend_lazy_object_initialized(Z_OBJ_P(*struc))
254+
) {
255+
xdebug_str_add_literal(str, "class ");
256+
xdebug_str_add(str, ZSTR_VAL(Z_OBJCE_P(*struc)->name), 0);
257+
xdebug_str_add_literal(str, " { *uninitialized ghost* }");
258+
259+
break; /* Jump out of the function */
260+
}
261+
#endif
262+
263+
#if PHP_VERSION_ID >= 80100
247264
if (ce->ce_flags & ZEND_ACC_ENUM) {
248265
zval *case_name_zval = zend_enum_fetch_case_name(Z_OBJ_P(*struc));
249266
xdebug_str_add_fmt(str, "enum %s::%s", ZSTR_VAL(ce->name), Z_STRVAL_P(case_name_zval));

tests/base/bug02375.inc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
class Example
4+
{
5+
private int $prop;
6+
7+
public function getProp(): int
8+
{
9+
return $this->prop;
10+
}
11+
}
12+
13+
$refClass = new ReflectionClass(Example::class);
14+
15+
$object = $refClass->newLazyGhost(function ($object) {
16+
echo "Initializer called\n";
17+
$ref = new ReflectionObject($object);
18+
$p = $ref->getProperty('prop');
19+
$p->setValue($object, 1);
20+
});
21+
22+
function foo(object $object)
23+
{
24+
try {
25+
throw new Exception();
26+
} catch (Exception $e) {
27+
}
28+
}
29+
30+
foo($object);
31+
32+
print_r($object);
33+
34+
$object->getProp();
35+
36+
print_r((array) $object); // When Xdebug is loaded, the array is empty.

tests/base/bug02375.phpt

380 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)