Skip to content

Commit b16761e

Browse files
committed
Fix GH-20073: Assertion failure in WeakMap offset operations on reference
Closes GH-20078.
1 parent 9b20618 commit b16761e

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ PHP NEWS
44

55
- Core:
66
. Fixed bug GH-19934 (CGI with auto_globals_jit=0 causes uouv). (ilutov)
7+
. Fixed bug GH-20073 (Assertion failure in WeakMap offset operations on
8+
reference). (nielsdos)
79

810
23 Oct 2025, PHP 8.3.27
911

Zend/tests/weakrefs/gh20073.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
GH-20073 (Assertion failure in WeakMap offset operations on reference)
3+
--FILE--
4+
<?php
5+
$obj = new stdClass;
6+
$map = new WeakMap;
7+
$integer = 1;
8+
$map[$obj] = 0;
9+
$map[$obj] =& $integer;
10+
$integer++;
11+
var_dump($map[$obj], $map->offsetGet($obj));
12+
?>
13+
--EXPECT--
14+
int(2)
15+
int(2)

Zend/zend_weakrefs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ ZEND_METHOD(WeakMap, offsetGet)
702702
return;
703703
}
704704

705-
ZVAL_COPY(return_value, zv);
705+
RETURN_COPY_DEREF(zv);
706706
}
707707

708708
ZEND_METHOD(WeakMap, offsetSet)

0 commit comments

Comments
 (0)