create(ParserFactory::PREFER_PHP7); $finder = new NodeFinder; $resolver = new NodeTraverser(new NameResolver()); $printer = new Standard(); foreach ($i as [$file]) { $f = file_get_contents($file); try { $parsed = $resolver->traverse($parser->parse($f)); } catch (\Throwable) { continue; } foreach ($finder->findInstanceOf($parsed, FunctionLike::class) as $f) { if ($f instanceof ArrowFunction) continue; if ($f->stmts === null) continue; $f->stmts = [new Foreach_( new Array_([new ArrayItem(new LNumber(0))]), new Variable('____'), ['stmts' => $f->stmts] )]; } file_put_contents($file, $printer->prettyPrintFile($parsed)); }