Skip to content

Commit 27976d7

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
2 parents fe984c7 + 753645a commit 27976d7

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

ext/spl/spl_fixedarray.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,12 @@ static void spl_fixedarray_object_write_dimension_helper(spl_fixedarray_object *
414414
zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0);
415415
return;
416416
} else {
417-
zval_ptr_dtor(&(intern->array.elements[index]));
418-
ZVAL_COPY_DEREF(&intern->array.elements[index], value);
417+
/* Fix #81429 */
418+
zval *ptr = &(intern->array.elements[index]);
419+
zval tmp;
420+
ZVAL_COPY_VALUE(&tmp, ptr);
421+
ZVAL_COPY_DEREF(ptr, value);
422+
zval_ptr_dtor(&tmp);
419423
}
420424
}
421425

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
--TEST--
2+
SplFixedArray::setSize in offsetSet destructor (#81429)
3+
--FILE--
4+
<?php
5+
$values = new SplFixedArray(1);
6+
$values->offsetSet(0, new HasDestructor());
7+
$values->offsetSet(0, false);
8+
echo "Done\n";
9+
10+
class HasDestructor {
11+
public function __destruct() {
12+
global $values;
13+
var_dump($values);
14+
$values->setSize($values->getSize() - 1);
15+
var_dump($values);
16+
}
17+
}
18+
19+
$values->setSize(5);
20+
$values->offsetSet(4, new HasDestructor());
21+
echo "Done\n";
22+
--EXPECT--
23+
object(SplFixedArray)#1 (1) {
24+
[0]=>
25+
bool(false)
26+
}
27+
object(SplFixedArray)#1 (1) {
28+
[0]=>
29+
bool(false)
30+
}
31+
Done
32+
Done
33+
object(SplFixedArray)#1 (5) {
34+
[0]=>
35+
NULL
36+
[1]=>
37+
NULL
38+
[2]=>
39+
NULL
40+
[3]=>
41+
NULL
42+
[4]=>
43+
object(HasDestructor)#2 (0) {
44+
}
45+
}
46+
object(SplFixedArray)#1 (4) {
47+
[0]=>
48+
NULL
49+
[1]=>
50+
NULL
51+
[2]=>
52+
NULL
53+
[3]=>
54+
NULL
55+
}

0 commit comments

Comments
 (0)