Monday, March 14, 2011

Nasty Zend Framework Module BootStrapping Issue Solved

You have been building individual mini-applications based on Zend Framework and then finally it's time to integrate them with the rest of your gargantuan application. You are happy that you were able to develop them individually by using the modular architecture of Zend Framework by a simple "drop" and "bootstrap" methodology. And then, you encounter this nasty fatal error.
Fatal error: Maximum function nesting level of '100' reached, aborting
I almost gave up using Zend Framework for this but this is what you get for high degree of flexibility (ZF rocks with this and you still get to be a high-end developer) and not to mention FREE. So if you're here reading my article, you're most likely having the same headache as I did before. Your lucky day!  Here's the problem and solution.

You have most probably extended your bootstrap class to Zend_Application_Bootstrap_Bootstrap within the scope of the module. You have been individually working on them and most likely haven't updated your bootstrap file to be a "module" which is to extend it to Zend_Application_Module_Bootstrap.

application/modules/some/Bootstrap.php
class Some_Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    
}
It should be,
class Some_Bootstrap extends Zend_Application_Module_Bootstrap
{
    
}

The module bootstrap (Zend_Application_Module_Bootstrap) is inherited from the main bootstrap (Zend_Application_Bootstrap_Bootstrap). The main bootstrap then calls the module bootstraps calling through the Resource plugins. So by extending the main bootstrap to the module context, the main bootstrap calls another main bootstrap when its called and the recursive call loop becomes infinite and throws the exception above.

Caution: You might not become aware of this error until too late in the game if you are suppressing errors. As a best practice, always have error_reporting set to E_STRICT and display_errors to ON during development.
  • Related Links Widget for Blogspot

No comments: