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

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -