Skip to content

Commit d9651a9

Browse files
committed
Fix GH-9697: array_walk($ffiInstance, function () {}) crashes due to expecting mutable array
1 parent b43e494 commit d9651a9

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

ext/ffi/tests/gh9697.phpt

+14
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+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("ffi")) die("skip ffi extension not available");
6+
?>
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

+4
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,10 @@ static int php_array_walk(zval *array, zval *userdata, int recursive) /* {{{ */
13331333
uint32_t ht_iter;
13341334
int result = SUCCESS;
13351335

1336+
if (zend_hash_num_elements(target_hash) == 0) {
1337+
return result;
1338+
}
1339+
13361340
/* Set up known arguments */
13371341
ZVAL_UNDEF(&args[1]);
13381342
if (userdata) {

0 commit comments

Comments
 (0)