The key part to notice on the original code is this:
"return ($parsed_tpl);"
Note the double-quotes, meaning the variable will be expanded in the string before passing it to create_function
. Then the expanded form will form the body of the function.
In other words, the actual code of the created function will be completely different every time - it won't just return the string, it will execute it as PHP code.
To achieve the same effect in current PHP, you need to use the eval function:
return eval("return ($parsed_tpl);");
You also have two mistakes in your attempt:
$e=null
isn't an assignment, it's a default value for the parameter; it doesn't need a semicolon
- You have to "capture" the
$parsed_tpl
variable with the use
keyword to use it inside the function
The format is this:
$my_anonymous_function =
function($some_param, $next_param='default value', $another='another default')
use ($something_captured, $something_else) {
/* body of function using those 5 variables*/
};