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
Posted by Matthew Weier O'Phinney (matthew) on 2008-10-28T17:47:12.000+0000
Updated in trunk.
Posted by Wil Sinclair (wil) on 2008-11-13T14:10:23.000+0000
Changing issues in preparation for the 1.7.0 release.
Posted by Raphael Dehousse (thymus) on 2009-11-04T08:02:44.000+0000
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
Posted by Raphael Dehousse (thymus) on 2009-11-22T23:59:07.000+0000
Fixed in ZF-8354