Erro de include no Zend_Loader

Português
,

Olá.

Hoje me deparei com um problema no Zend Framework e seu autoloader de classes, onde uma chamada ao class_exists dispara o autoloader do Zend Framework. A função tem uma opção de não disparar o autoloader, porém, ela sempre retorna false para objetos que são carregados dinamicamente via Zend_Loader.

Além disso, se eu uso class_exists sem desabilitar o autoloader, eu recebo um warning o arquivo com a classe não exista, isso por que o Zend_Loader não faz a verificação se o arquivo existe, ele apenas inclui.

A solução seria mudar o Zend/Loader.php, fazendo com que ele verifique se o arquivo da classe antes de tentar incluir, e isso deve ser feito dentro do método loadFile.

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;
}

Até mais.