dev.mraj dev.mraj - 4 months ago 6
PHP Question

Calling Nested Lamda Function in PHP

is that possible to call lamda function in nesting way

<?php
$func=function() use($something,$func /** as you know it will be undefined so what could be other way arround**/){
if($something){
$func();
}
}

Answer

$func is not defined yet when you pass it to $func. $func will only be defined right after the function definition, which is a little bit too late for this to work.

The easy work around is as follows:

$func = null;
$func = function() use (&$func) {

}
Comments