It's worth noting that functions created via create_function won't be garbage-collected, which can cause some obvious problems.
This article about partial application may also be of interest to PHP hackers with an interest in functional programming.
This article about partial application may also be of interest to PHP hackers with an interest in functional programming.
function lambda( $code )
{
if( !preg_match( '/return/', $code ) )
{
$code = preg_replace('/^(.*;(?!\s*$))?/s', "$1 return ", $code);
}
$code .= ';';
$response = create_function('$_=null,$_1=null,$_2=null,$_3=null,$_4=null,$_5=null', $code);
if( !$response )
{
error_log("lambda($code) failed");
}
return $response;
}
This converts: $func = create_function('$v','return htmlenties($v,ENT_QUOTES);');
array_map($func, $data);
Into: array_map(lambda('htmlenties($_, ENT_QUOTES)'), $data);