Hi Matthew,
having these show is probably a good thing, as
it shows potential breakage in your code
That isn't necessarily the case. The reason this is an issue for me is that I'm using class_exists() to check if certain classes have been defined. class_exists() will use the registered autoload functions to attempt to load the class, and if they have no luck will obviously return false. In this instance, having PHP warnings show up when the class is not found is of no help at all, because that's nothing to do with an error in the code, it's not that I'm actually trying to use the class.

This is a problem for the development environment, and although display_errors is set to false on the production server, it will still pollute the error logs with warnings that shouldn't be there.

Although it doesn't explicitly say so, this line from the PHP docs implies that the auto load function should simply /try /to include the class, not require that is is successful in doing so.
By calling this function the scripting engine is given a last chance to load the class before PHP fails with an error.
If you were to try and use a class that none of the autoload functions could include, PHP would throw its own class not defined error.

There is also an issue when using multiple autoloads. What if Zend_Loader::autoload() isn't the last autoload function in the stack? And the particular class you're trying to use should be loaded by the last autoload? Zend_Loader::loadClass() is still going to throw a file not found error, despite the fact that the class may still get loaded.

Matthew Weier O'Phinney wrote:
-- Jack Sleight <[EMAIL PROTECTED]> wrote
(on Wednesday, 19 March 2008, 10:44 AM +0000):
Well, Zend_Loader::autoload() (which is the callback registered  by
Zend_Loader::registerAutoload()) actually wraps Zend_Loader::loadClass()
in a try/catch block, and returns a boolean false if the class was not
found.

PHP Warnings simply indicate that the file was not loaded; they are not
a fatal issue, but simply an indicator that something is potentially
wrong. In your production environments, I would expect you would have
display_errors off as it is, and these would never be seen. In your
development environment, having these show is probably a good thing, as
it shows potential breakage in your code.

I wouldn't re-open the issue, but if you feel strongly about it, I'd
recommend opening a separate issue asking for the following: that
Zend_Loader::registerAutoload() register an error handler that catches
only the warnings generated by include_once and suppresses them. And
then we can restart the discussion.


--
Jack

Reply via email to