PHP closure scope problem -
apparently $pid out of scope here. shouldn't "closed" in function? i'm sure how closures work in javascript example.
according articles php closures broken, cannot access this?
so how can $pid accessed closure function?
class myclass { static function gethdvdscol($pid) { $col = new pointcolumn(); $col->key = $pid; $col->parser = function($row) { print $pid; // undefined variable: pid }; return $col; } } $func = myclass::gethdvdscol(45); call_user_func($func, $row);
edit have gotten around use: $col->parser = function($row) use($pid)
. feel ugly.
you need specify variables should closed in way:
function($row) use ($pid) { ... }
Comments
Post a Comment