Include error on Zend_Loader

English
,

Hello.

Today I found a problem in Zend Framework and his class autoloader, where an class_exists function call fires the Zend Framework autoloader. The function has an option to ignore the autoloader, but any class that I need loaded by Zend_Loader will return false.

Then, if I call class_exists without disable autoloader, I got an file not exists PHP warning, that’s why Zend_Loader doesn’t check if the file exists, just include.

The trick is change Zend/Loader.php to check if file exists before include, and this must be wrote in loadFile method.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
public static function loadFile($filename, $dirs = null, $once = false)
{
    self::_securityCheck($filename);

    /**
     * Search in provided directories, as well as include_path
     */
    $incPath = false;
    if (!empty($dirs) && (is_array($dirs) || is_string($dirs))) {
        if (is_array($dirs)) {
            $dirs = implode(PATH_SEPARATOR, $dirs);
        }
        $incPath = get_include_path();
        set_include_path($dirs . PATH_SEPARATOR . $incPath);
    }

    /**
     * Try finding for the plain filename in the include_path.
     */
    if (!self::fileExists($filename)) {
        return false;
    }

    if ($once) {
        include_once $filename;
    } else {
        include $filename;
    }

    /**
     * If searching in directories, reset include_path
     */
    if ($incPath) {
        set_include_path($incPath);
    }

    return true;
}

public static function fileExists ($filename) {
    $paths = explode(PATH_SEPARATOR, get_include_path());
    foreach ($paths as $path) {
        if (file_exists($path . DIRECTORY_SEPARATOR . $filename)) {
            return true;
        }
    }
    return false;
}

Bye.