gpt4 book ai didi

php - 我可以立即评估匿名函数吗?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:45:32 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Immediately executing anonymous functions

我想立即评估一个匿名函数,而不是它在方法参数中显示为闭包对象。这可能吗?

例如:

$obj = MyClass;
$obj->Foo(function(){return "bar";}); // passes a Closure into Foo()
$obj->Foo(function(){return "bar";}()); // passes the string "bar" into Foo()?

第 3 行是非法语法——有什么办法可以做到这一点吗?

谢谢

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com