Issues

ZF-4736: Dispatcher contains unnecessary call to Zend_Loader::loadFile()

Description

The following (around line 337) from Zend_Controller_Dispatcher_Standard should be refactored:


$dispatchDir = $this->getDispatchDirectory();
$loadFile    = $dispatchDir . DIRECTORY_SEPARATOR . $this->classToFilename($className);
$dir         = dirname($loadFile);
$file        = basename($loadFile);

try {
    Zend_Loader::loadFile($file, $dir, true);
} catch (Zend_Exception $e) {
    require_once 'Zend/Controller/Dispatcher/Exception.php';
    throw new Zend_Controller_Dispatcher_Exception('Cannot load controller class "' . $className . '" from file "' . $file . '" in directory "' . $dir . '"');
}

The full file path is already known, so calling loadFile() is unnecessary overhead. Additionally, loadFile() does not throw an exception -- so there is no need to wrap it in a try/catch block. It would be sufficient to simply check that an include_once statement does not return a false value.

Comments

Updated in trunk.

Changing issues in preparation for the 1.7.0 release.

Hello,

This issue should be reopened because the include_once statement can generate a Warning if the file does not exists. It should be @include_once or check with file_exists

Thanks to fix this

Cheers,

Raphaƫl Dehousse

Fixed in ZF-8354