Apparently $pid is out of scope here. Shouldn't it be "closed" in with the function? I'm fairly sure that is how closures work in javascript for example.
According to some articles php closures are broken, so I cannot access this?
So how can $pid be accessed from this 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 I have gotten around it with use: $col->parser = function($row) use($pid). However I feel this is ugly.
$thiswithin the closure.