Skip to content

Commit d0d8e68

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix GH-17447: Assertion failure when array popping a self addressing variable
2 parents a4fa1e7 + ae3ab37 commit d0d8e68

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

ext/standard/array.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -3571,7 +3571,8 @@ PHP_FUNCTION(array_pop)
35713571
break;
35723572
}
35733573
}
3574-
RETVAL_COPY_DEREF(val);
3574+
RETVAL_COPY_VALUE(val);
3575+
ZVAL_UNDEF(val);
35753576

35763577
if (idx == (Z_ARRVAL_P(stack)->nNextFreeElement - 1)) {
35773578
Z_ARRVAL_P(stack)->nNextFreeElement = Z_ARRVAL_P(stack)->nNextFreeElement - 1;
@@ -3595,7 +3596,8 @@ PHP_FUNCTION(array_pop)
35953596
break;
35963597
}
35973598
}
3598-
RETVAL_COPY_DEREF(val);
3599+
RETVAL_COPY_VALUE(val);
3600+
ZVAL_UNDEF(val);
35993601

36003602
if (!p->key && (zend_long)p->h == (Z_ARRVAL_P(stack)->nNextFreeElement - 1)) {
36013603
Z_ARRVAL_P(stack)->nNextFreeElement = Z_ARRVAL_P(stack)->nNextFreeElement - 1;
@@ -3605,6 +3607,10 @@ PHP_FUNCTION(array_pop)
36053607
zend_hash_del_bucket(Z_ARRVAL_P(stack), p);
36063608
}
36073609
zend_hash_internal_pointer_reset(Z_ARRVAL_P(stack));
3610+
3611+
if (Z_ISREF_P(return_value)) {
3612+
zend_unwrap_reference(return_value);
3613+
}
36083614
}
36093615
/* }}} */
36103616

ext/standard/tests/array/gh17447.phpt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
GH-17447 (Assertion failure when array poping a self addressing variable)
3+
--FILE--
4+
<?php
5+
$input[] = &$input;
6+
var_dump(array_pop($input), $input);
7+
?>
8+
--EXPECT--
9+
array(0) {
10+
}
11+
array(0) {
12+
}

0 commit comments

Comments
 (0)