Why do my anonymous functions evaluate to NULL in Symfony 2.0?

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

[28-Nov-2011 16:51:26] PHP Fatal error: exception for the exception "InvalidArgumentException" with the message "The expected call is expected in AnnotationRegistry :: registerLoader () '.

Digging deeper, I found that an anonymous function is being passed to the registerLoader function.

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

It looks good, right? To be safe, I threw a check:

 var_dump(gettype($callable)); 

Which returns NULL, which obviously cannot be called. I just upgraded to PHP 5.3.2, and according to phpversion() , this version will be used.

I ran a one-time script outside of Symfony and everything behaved correctly.

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

// line (6) "object"

Does anyone have any thoughts as to why I see other behavior around anonymous functions inside the Symfony environment?

+4
source share
1 answer

Have you checked your configuration as stated in the symfony docs ?

This should tell you if you are missing something that is required to run Symfony.

0
source

Source: https://habr.com/ru/post/1383539/


All Articles