xref: /PHP-8.1/Zend/tests/bug78502.phpt (revision e81751ce)
1--TEST--
2Bug #78502: Incorrect stack size calculation for indirectly recursive function call
3--FILE--
4<?php
5
6$tree = [
7    'name' => 'a',
8    'quant' => 1,
9    'children' => [
10        ['name' => 'b', 'quant' => 1],
11        ['name' => 'c', 'quant' => 1, 'children' => [
12            ['name' => 'd', 'quant' => 1],
13        ]],
14    ],
15];
16
17function tree_map($tree, $recursive_attr, closure $callback){
18    if(isset($tree[$recursive_attr])){
19        $tree[$recursive_attr] = array_map(function($c) use($recursive_attr, $callback){
20            return tree_map($c, $recursive_attr, $callback);
21        }, $tree[$recursive_attr]);
22    }
23    return $callback($tree);
24}
25
26tree_map($tree, 'children', function ($node) {});
27
28?>
29===DONE===
30--EXPECT--
31===DONE===
32