I would like to bind a variable to a function's scope, I can do this in php use the 'use' keyword after PHP 5.3, however how do I do the equivalent in versions < PHP 5.3?
test_use_keyword(); function test_use_keyword(){ $test =2; $res=array_map( function($el) use ($test){ return $el * $test; }, array(3) ); print_r($res); }
Normally through globals, seriously. Although hacks could be used to mimic the functionality, like partial functions in php. Extracted from article:
And only after that could you have something like.
Not... worth... it.
You can use a global variable, but you should always avoid globals variables whereever possible. As a suggestion, without knowing, what you are trying to solve with this
Also possible are the good old lambdas