嵌套lambda函數是可以調用lambda函數嵌套在這樣調用PHP中
<?php
$func=function() use($something,$func /** as you know it will be undefined so what could be other way arround**/){
if($something){
$func();
}
}
嵌套lambda函數是可以調用lambda函數嵌套在這樣調用PHP中
<?php
$func=function() use($something,$func /** as you know it will be undefined so what could be other way arround**/){
if($something){
$func();
}
}
$func
沒有定義,當你把它傳遞給$func
。 $func
只會在函數定義之後定義,這對於它的工作來說有點太晚了。
最簡單的解決辦法如下:
$func = null;
$func = function() use (&$func) {
}
不錯的一個...我從來沒有想過使用這個參考... –
我也是...... –
use $func
能不能成功,因爲$func
不會後才拉姆達創作已經完成定義並返回蘭巴。 PHP不能時間旅行。
你也不能這樣做:
$func = '';
$func = function() use $something, $func ....;
雖然該$func is not defined
各地得到,它也「鎖定」的$func
當時的拉姆達的創造的價值到拉姆達:
php > $foo = 'bar';
php > $baz = function() use($foo) { echo $foo; };
php > $baz();
bar
php > $foo = 'qux';
php > $baz();
bar
爲什麼要投票?是不是有關PHP –
這些被允許http://stackoverflow.com/questions/3737139/reference-what-do-various-symbols-mean-in-php?rq=1但不允許真正的問題。 –
那麼在你想用上面說的東西的定義中呢? –