-- A.J. Brown <[email protected]> wrote
(on Tuesday, 03 November 2009, 07:59 PM -0500):
> I'm trying to supress errors with the Zend Autoloader, but it's still
> throwing them. In this specific case, I'm dynamically ceating a class
> if it doesn't already exist. I'm calling suppressNotFoundWarnings(
> true ).
>
> Here's my code:
>
> http://www.pastie.org/682603
>
> On line 13, I'm getting a Zend_Exception saying that CP/Form/Login.php
> not found and CP_Form_Login does not exist. Here's that line:
>
> if( @$autoloader->autoload( $class ) ) {
>
> even wrapping it in a Try/Catch doesn't catch the exception. The best
> part is that further down in the code, the class is still declared,
> and the code continues to run.
>
> the CP_ namespace is registered to the autoloader at bootstrap. (I
> confirmed this through debugging).
You're confusing exceptions with errors. Zend_Loader_Autoloader does not
throw exceptions within its autoload() method (it's considered a bad
practice, and PHP itself behaves badly when it happens); this is why the
try/catch does not work. What's actually happening is that PHP's
include() function is raising a PHP warning when it can't find the
related file in question.
What *is* odd to me is that the autoloader is not suppressing the errors
when you've specifically requested it do so. I've just tried this
locally with the following:
$autoloader->suppressNotFoundWarnings(true);
if (!$autoloader->autoload('Zend_Foo_Bar')) {
echo 'Not found';
exit;
}
echo 'Found';
With the warnings suppressed, it works as expected; without, I get
the PHP warning, again, as expected.
So, a few questions:
* What version of ZF are you using?
* Can you provide *all* code indicating how you've configured the
autoloader?
* Is the "CP_" namespace registered with the autoloader? If not, do you
have another autoloader registered that would be handling it?
Based on what you've presented, I have to assume that there's some other
configuration issue that's leading to the error.
--
Matthew Weier O'Phinney
Project Lead | [email protected]
Zend Framework | http://framework.zend.com/