File tree 3 files changed +51
-2
lines changed
3 files changed +51
-2
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,8 @@ PHP NEWS
43
43
- Standard:
44
44
. Fixed bug GH-16905 (Internal iterator functions can't handle UNDEF
45
45
properties). (nielsdos)
46
+ . Fixed bug GH-16957 (Assertion failure in array_shift with
47
+ self-referencing array). (nielsdos)
46
48
47
49
- Streams:
48
50
. Fixed network connect poll interuption handling. (Jakub Zelenka)
Original file line number Diff line number Diff line change @@ -3632,7 +3632,8 @@ PHP_FUNCTION(array_shift)
3632
3632
}
3633
3633
idx ++ ;
3634
3634
}
3635
- RETVAL_COPY_DEREF (val );
3635
+ RETVAL_COPY_VALUE (val );
3636
+ ZVAL_UNDEF (val );
3636
3637
3637
3638
/* Delete the first value */
3638
3639
zend_hash_packed_del_val (Z_ARRVAL_P (stack ), val );
@@ -3686,7 +3687,8 @@ PHP_FUNCTION(array_shift)
3686
3687
}
3687
3688
idx ++ ;
3688
3689
}
3689
- RETVAL_COPY_DEREF (val );
3690
+ RETVAL_COPY_VALUE (val );
3691
+ ZVAL_UNDEF (val );
3690
3692
3691
3693
/* Delete the first value */
3692
3694
zend_hash_del_bucket (Z_ARRVAL_P (stack ), p );
@@ -3710,6 +3712,10 @@ PHP_FUNCTION(array_shift)
3710
3712
}
3711
3713
3712
3714
zend_hash_internal_pointer_reset (Z_ARRVAL_P (stack ));
3715
+
3716
+ if (Z_ISREF_P (return_value )) {
3717
+ zend_unwrap_reference (return_value );
3718
+ }
3713
3719
}
3714
3720
/* }}} */
3715
3721
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ GH-16957 (Assertion failure in array_shift with self-referencing array)
3
+ --FILE--
4
+ <?php
5
+ $ new_array = array (&$ new_array , 1 , 'two ' );
6
+ var_dump ($ shifted = array_shift ($ new_array ));
7
+ var_dump ($ new_array );
8
+ var_dump ($ new_array === $ shifted );
9
+
10
+ $ new_array2 = array (&$ new_array2 , 2 => 1 , 300 => 'two ' );
11
+ var_dump ($ shifted = array_shift ($ new_array2 ));
12
+ var_dump ($ new_array2 );
13
+ var_dump ($ new_array2 === $ shifted );
14
+ ?>
15
+ --EXPECT--
16
+ array(2) {
17
+ [0]=>
18
+ int(1)
19
+ [1]=>
20
+ string(3) "two"
21
+ }
22
+ array(2) {
23
+ [0]=>
24
+ int(1)
25
+ [1]=>
26
+ string(3) "two"
27
+ }
28
+ bool(true)
29
+ array(2) {
30
+ [0]=>
31
+ int(1)
32
+ [1]=>
33
+ string(3) "two"
34
+ }
35
+ array(2) {
36
+ [0]=>
37
+ int(1)
38
+ [1]=>
39
+ string(3) "two"
40
+ }
41
+ bool(true)
You can’t perform that action at this time.
0 commit comments