Zend_Loader, the silent killer

Update 1st May 2009: Good news, Zend Framework 1.8 defaults to no longer suppressing errors in loading classes (not sure how much of their library has been converted to use this though)

A good article on the autoloader changes:

http://devzone.zend.com/article/4525

Several times during website development, I have come across scripts which die without errors, so I try and debug the pages, finding which functions/includes it is getting to before it dies, narrowing it down. The code I usually come across which causes this is in the Zend Framework in the form of:

@Zend_Loader::loadClass('My_Class');

Note the @, this silences any errors/warnings/notices that occur inside the code that the function calls.

Taking this away always leads to showing the much more helpful information e.g.:

Parse error: syntax error, unexpected T_STRING in ...

You see Zend_Loader, if it can’t find My_Class already loaded, will require_once ‘My/Class.php’. If any of the code inside that file causes an error of any kind, it will not get reported back to the developer. Also, if the error is fatal, the entire script will stop, giving no indication of where it broke.

Now a message to all Zend Framework developers, I implore you, please remove the @ characters from your Zend_Loader calls! Life will be much simpler if you do this. Silencing errors using this should be used sparingly, and this situation it should not be the case.