You could probably use a Closure, to do just that...
Edit : took some time to remember the syntax, but here's what it would look like :
function foo()
{
$l = "xyz";
$bar = function () use ($l)
{
var_dump($l);
};
$bar();
}
foo();
And, running the script, you'd get :
$ php temp.php
string(3) "xyz"
A couple of note :
- You must put a
;
after the function's declaration !
- You could
use
the variable by reference, with a &
before it's name : use (& $l)
For more informations, as a reference, you can take a look at this page in the manual : Anonymous functions
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…