Zend Framework closure cache problem

Hello,

I have a problem with Zend Framework 3 on production. When I have config_cache_enabled set on true, I see this error:

Fatal error: Uncaught Error: Call to undefined method Closure::__set_state() in /home/users/devmonitoring/data/cache/module-config-cache.application.config.cache.php:67 

Stack trace: 
#0 /home/users/devmonitoring/vendor/zendframework/zend-modulemanager/src/Listener/ConfigListener.php(392): include() 
#1 /home/users/devmonitoring/vendor/zendframework/zend-modulemanager/src/Listener/ConfigListener.php(70): Zend\ModuleManager\Listener\ConfigListener->getCachedConfig() 
#2 /home/users/devmonitoring/vendor/zendframework/zend-modulemanager/src/Listener/DefaultListenerAggregate.php(98): Zend\ModuleManager\Listener\ConfigListener->__construct(Object(Zend\ModuleManager\Listener\ListenerOptions)) 
#3 /home/users/devmonitoring/vendor/zendframework/zend-modulemanager/src/Listener/DefaultListenerAggregate.php(42): Zend\ModuleManager\Listener\DefaultListenerAggregate->getConfigListener() 
#4 /home/users/devmonitoring/vendor/zendframework/zend-mvc/src/Service/ModuleManagerFactory.php(77): Zend\ModuleManager\Listener\DefaultListenerAggregate-> in /home/users/devmonitoring/data/cache/module-config-cache.application.config.cache.php on line 67

I tried to clear cache, but this error still happens.

It was like that even in zf2. You cannot use closures in your array config together with config cache, see: https://docs.zendframework.com/tutorials/advanced-config/#use-cases-for-service-configuration-methods

If you have closures in config, move them to service configuration methods: https://docs.zendframework.com/tutorials/advanced-config/#configuration-mapping-table

2 Likes

Thanks, it works well!