Skip to content

Commit 626e909

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fix GH-9697: array_walk($ffiInstance, function () {}) crashes due to expecting mutable array
2 parents 182c8ac + fa2c519 commit 626e909

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

ext/ffi/tests/gh9697.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
GH-9697 (array_walk($ffiInstance, function () {}) crashes due to expecting mutable array)
3+
--EXTENSIONS--
4+
ffi
5+
--INI--
6+
ffi.enable=1
7+
--FILE--
8+
<?php
9+
$x = FFI::new('int');
10+
array_walk($x, function($x) { echo "test\n"; });
11+
?>
12+
DONE
13+
--EXPECT--
14+
DONE

ext/standard/array.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,10 @@ static int php_array_walk(
12721272
* levels of recursion. */
12731273
zend_fcall_info fci = context->fci;
12741274

1275+
if (zend_hash_num_elements(target_hash) == 0) {
1276+
return result;
1277+
}
1278+
12751279
/* Set up known arguments */
12761280
ZVAL_UNDEF(&args[1]);
12771281
if (userdata) {

0 commit comments

Comments
 (0)