Assertion fail when returning an anonymous function.
Opened this issue · 6 comments
quanyang commented
In the following code example, an anonymous function is returned, acting like a closure. However, the Printer class expects a function name.
function generateComparisonFunctionForKey($key) {
return function ($left, $right) use ($key) {
if ($left[$key] == $right[$key])
return 0;
else
return ($left[$key] < $right[$key]) ? -1 : 1;
};
}
Error:
Warning: assert(): Assertion failed in /Users/<redacted>/php-cfg/lib/PHPCfg/Printer.php on line 46
nikic commented
The assertion error is fixed by d43ed9f.
However the way we handle bound closure variables currently is not good (and for the reference case outright violates SSA). Closure body also shouldn't be part of the same CFG really...
quanyang commented
Yea, seems like an issue I'll face later.
nikic commented
In 0d54187 I've introduced a Func structure, so each function has a clearly separated CFG. The Funcs are collected in a Script, which is what is returned by the parser now.
Closures still need extra work for the use variable handling.
quanyang commented
Does GraphViz still work?