4

I just started playing around with Symfony 2.0 and immediately ran into an error:

[28-Nov-2011 16:51:26] PHP Fatal error: Uncaught exception 'InvalidArgumentException' with message 'A callable is expected in AnnotationRegistry::registerLoader().'

Digging deeper, I found that an anonymous function was getting passed into the registerLoader function.

$callable = function($class) use ($loader)
{
  $loader->loadClass($class);
  return class_exists($class, false);
};

AnnotationRegistry::registerLoader($callable);

Looks fine, right? Just to be safe, I threw in a check:

var_dump(gettype($callable));

Which returned NULL, which is obviously not callable. I just upgraded to PHP 5.3.2, and according to phpversion() that's the version that is getting used.

I ran a one-off script outside of the Symfony environment and everything behaved correctly.

$foo = function()
{
    echo 'foo';
};

var_dump(gettype($foo));

//string(6) "object"

Anyone have any thoughts as to why I'm seeing different behavior around anonymous functions inside the Symfony environment?

4

1 回答 1

0

您是否按照Symfony 文档中的说明检查了您的配置?

这应该会告诉您是否缺少运行 Symfony 所需的任何内容

于 2011-11-30T13:37:32.813 回答