diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index e5dc6898eaf4..fe427bb9feb0 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1224,8 +1224,9 @@ static HashTable *sxe_get_gc(zend_object *object, zval **table, int *n) /* {{{ * php_sxe_object *sxe; sxe = php_sxe_fetch_object(object); - *table = NULL; - *n = 0; + /* sxe->tmp is handed out by reference and can hold the element itself */ + *table = &sxe->tmp; + *n = 1; return sxe->properties; } /* }}} */ diff --git a/ext/simplexml/tests/get_gc_tmp_cycle.phpt b/ext/simplexml/tests/get_gc_tmp_cycle.phpt new file mode 100644 index 000000000000..3750d6f54365 --- /dev/null +++ b/ext/simplexml/tests/get_gc_tmp_cycle.phpt @@ -0,0 +1,25 @@ +--TEST-- +SimpleXMLElement: a cycle through the by-reference property of a missing element is collected +--EXTENSIONS-- +simplexml +--FILE-- +'); +$w = WeakReference::create($x); +$r = &$x->n; +$r = $x; +unset($r, $x); +gc_collect_cycles(); +var_dump($w->get() === null); + +function g(&$o, $v) { $o = $v; } +$x = simplexml_load_string(''); +$w = WeakReference::create($x); +g($x->n, $x); +unset($x); +gc_collect_cycles(); +var_dump($w->get() === null); +?> +--EXPECT-- +bool(true) +bool(true)