相关疑难解决方法(0)

关闭与匿名功能(差异?)

可能的重复:
什么是PHP或Javascript中的Closures/Lambda外行术语?
'闭包'和'lambda'有什么区别?

嗨,

我一直无法找到一个明确解释闭包和匿名函数之间差异的定义.

我看到的大多数参考文献清楚地指出它们是不同的"事物",但我似乎无法理解为什么.

有人可以帮我简化一下吗?这两种语言功能之间有哪些具体差异?在哪些情况下哪一个更合适?

closures anonymous-function

67
推荐指数
1
解决办法
2万
查看次数

为什么以及如何在PHP中使用匿名函数?

PHP 5.3提供匿名函数.
我应该使用它们还是避免使用它们?如果是这样,怎么样?

编辑 ; 刚刚用php匿名函数发现了一些不错的技巧......

$container           = new DependencyInjectionContainer();
$container->mail     = function($container) {};
$conteiner->db       = function($container) {};
$container->memcache = function($container) {};
Run Code Online (Sandbox Code Playgroud)

php anonymous-function

44
推荐指数
3
解决办法
4万
查看次数

无法将类Closure的对象转换为string:filename.

function convert($currencyType)
{
    $that = $this;
    return $result = function () use ($that) 
    {
        if (!in_array($currencyType, $this->ratio))
                return false;

        return ($this->ratio[$currencyType] * $this->money); //a float number
    };
}

$currency = new Currency();
echo $currency->convert('EURO');
Run Code Online (Sandbox Code Playgroud)

怎么了?

我收到错误消息:

Catchable fatal error: Object of class Closure could not be converted to string
Run Code Online (Sandbox Code Playgroud)

php

9
推荐指数
3
解决办法
3万
查看次数

标签 统计

anonymous-function ×2

php ×2

closures ×1