自 php 7.4 起无法使用 array_walk 迭代迭代器

Tad*_*das 7 php iterator array-walk

$iterator = new ArrayIterator([1, 2]);
array_walk($iterator, function($item) {echo $item . PHP_EOL;});
Run Code Online (Sandbox Code Playgroud)

这段 php 代码在 php 7.3 中输出了项目(1 和 2),但在 php 7.4 中没有输出任何内容。谁能解释 php 7.4 中导致此更改的更改?我在变更日志中找不到任何与此相关的内容。

Tom*_*far 0

以防万一有人需要解决这个问题,您可以将迭代器转换为数组。

$iterator = new ArrayIterator([1, 2]);
$array = iterator_to_array($iterator);
array_walk($array, function($item) {echo $item . PHP_EOL;});
Run Code Online (Sandbox Code Playgroud)

https://3v4l.org/Xq9Dc