mirror of
https://github.com/php/php-src.git
synced 2024-09-21 18:07:23 +00:00
Allow removing non-existing key from WeakMap
In line with usual PHP semantics. This previously triggered an assertion failure.
This commit is contained in:
parent
ce83ec8790
commit
614c0b846e
@ -46,6 +46,9 @@ try {
|
||||
echo $e->getMessage(), "\n";
|
||||
}
|
||||
|
||||
// It's okay to unset an object that's not in the map.
|
||||
unset($map[new stdClass]);
|
||||
|
||||
echo "\nIndirect modification:\n";
|
||||
$map[$obj] = [];
|
||||
$map[$obj][] = 42;
|
||||
|
@ -372,6 +372,11 @@ static void zend_weakmap_unset_dimension(zend_object *object, zval *offset)
|
||||
|
||||
zend_weakmap *wm = zend_weakmap_from(object);
|
||||
zend_object *obj_key = Z_OBJ_P(offset);
|
||||
if (!zend_hash_index_exists(&wm->ht, (zend_ulong) Z_OBJ_P(offset))) {
|
||||
/* Object not in WeakMap, do nothing. */
|
||||
return;
|
||||
}
|
||||
|
||||
zend_weakref_unregister(obj_key, ZEND_WEAKREF_ENCODE(wm, ZEND_WEAKREF_TAG_MAP));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user