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

Issue Type: Performance Improvement Created: 2008-10-28T17:40:01.000+0000 Last Updated: 2009-11-22T23:59:07.000+0000 Status: Resolved Fix version(s): - 1.7.0 (17/Nov/08)

Reporter: Matthew Weier O'Phinney (matthew) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Controller

Related issues: Attachments:


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

<pre class="highlight">
$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.


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


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


Raphaƫl Dehousse

Posted by Raphael Dehousse (thymus) on 2009-11-22T23:59:07.000+0000

Fixed in ZF-8354

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.