Skip to content

Commit adcd43d

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Make weak ref notify robust against bailout
2 parents a01d739 + a4b209f commit adcd43d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Exception during WeakMap destruction during shutdown
3+
--FILE--
4+
<?php
5+
$map = new WeakMap;
6+
$obj = new stdClass;
7+
$map[$obj] = new class {
8+
function __destruct() {
9+
throw new Exception("Test");
10+
}
11+
};
12+
?>
13+
--EXPECTF--
14+
Fatal error: Uncaught Exception: Test in %s:%d
15+
Stack trace:
16+
#0 [internal function]: class@anonymous->__destruct()
17+
#1 {main}
18+
thrown in %s on line %d

Zend/zend_weakrefs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ void zend_weakrefs_notify(zend_object *object) {
157157
ZEND_ASSERT(tagged_ptr && "Tracking of the IS_OBJ_WEAKLY_REFERENCE flag should be precise");
158158
#endif
159159
if (tagged_ptr) {
160-
zend_weakref_unref(obj_addr, tagged_ptr);
161160
zend_hash_index_del(&EG(weakrefs), obj_addr);
161+
zend_weakref_unref(obj_addr, tagged_ptr);
162162
}
163163
}
164164

0 commit comments

Comments
 (0)