ZF-4057: Zend Loader produces a lot of unnecessary "file not found" warnings

Description

The Zend Loader component will produce a lot of "file not found" warnings because it uses 'fopen' to probe the existence of files.

Instead of using fopen directly, why not use file_exists first to test for the existence and then use 'fopen' to open the files??

This should be an easy fix.

Comments

I think it duplicates ZF-2985.

We prefix fopen() with the "@" to silence such warnings; if you're seeing them, they're likely showing up in your logs or you have ext/scream enabled. While we'd prefer not to have these warnings at all, there are some reasons for them.

The fix isn't as easy as you might expect. Because this functionality is used everywhere, and because it may be invoked sometimes thousands of times in a request, we run into performance issues. Every stat call you do is an I/O call to the disk -- and these are very expensive. Add to this the fact that loadClass() and isReadable() are actually testing against the include_path: the result is that if the file we're looking for is N directories into the path, we end up having N*2 stat calls until we reach our file... if indeed it's ever found and/or readable. (This is actually why we use fopen() -- because it looks on the include_path. Unless you have PHP >=5.3.2 which introduces stream_resolve_include_path(), there's no other function in PHP that has the ability to test against the include_path without userland iteration.)

This last is also why file_exists() will not work -- because we're testing a file against the include_path. To use file_exists() correctly in this situation, we'd have to iterate the include_path and test against each segment until we got a hit, or all paths had been tested.