When debugging, if you encounter a closure, I would like to know the specific closure. However, the IDE generally does not display the function body of the closure. So I copied a function from the Internet to show the contents of the closure function.
functionMy_closure_dump (Closure$c) { $str= ' function ('; $r=New\reflectionfunction ($c); $params=Array(); foreach($r->getparameters () as $p) { $s= ' '; if($p-IsArray ()) { $s. = ' array '; } Else if($p-getclass ()) { $s.=$p->getclass ()->name. ‘ ‘; } if($p-ispassedbyreference ()) { $s. = ' & '; } $s. = ' $ '.$p-name; if($p-isoptional ()) { $s. = ' = '.Var_export($p->getdefaultvalue (),TRUE); } $params[]=$s; } $str.=implode(‘, ‘,$params); $str. = ') {'.Php_eol; $lines=file($r-GetFileName ()); for($l=$r->getstartline ();$l<$r->getendline ();$l++) { $str.=$lines[$l]; } return $str;}
View the function body of a closure function