In Magento 1, if I use the full Magento class name in a factory method, I'm able to instantiate an object

//trying full class name instead of catalog/product
$object = Mage::getModel('Mage_Catalog_Model_Product');

However, the same thing won't work for helpers. If you try


You get

Warning: include(Mage/Mage/Core/Helper/Url/Helper/Data.php): failed to open stream: No such file or directory  in /path/to/magentolib/Varien/Autoload.php on line 93

#0 /path/to/magentolib/Varien/Autoload.php(93): mageCoreErrorHandler(2, 'include(Mage/Ma...', '/path/to/magent...', 93, Array)
#1 /path/to/magentolib/Varien/Autoload.php(93): Varien_Autoload::autoload()
#2 [internal function]: Varien_Autoload->autoload('Mage_Mage_Core_...')
#3 /path/to/magentoapp/Mage.php(547): spl_autoload_call('Mage_Mage_Core_...')
#4 /path/to/magentoapp/code/local/Sebastianjuffar/Commercebug/controllers/IndexController.php(11): Mage::helper('Mage_Core_Helpe...')
#5 /path/to/magentoapp/code/core/Mage/Core/Controller/Varien/Action.php(418): Sebastianjuffar_Commercebug_IndexController->indexAction()
#6 /path/to/magentoapp/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('index')
#7 /path/to/magentoapp/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#8 /path/to/magentoapp/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#9 /path/to/magentoapp/Mage.php(684): Mage_Core_Model_App->run(Array)
#10 /path/to/magentoindex.php(87): Mage::run('', 'store')
#11 {main}

What's going on?

  • 2
    You got this from twitter didn't you? :)
    – Marius
    Jun 27, 2014 at 15:30
  • 1
    @marius you beat me to it. Twitter-questions-as-a-service.
    – philwinkle
    Jun 27, 2014 at 15:30
  • @Marius Yeah — trying to encourage the questions I get on twitter to come here instead.
    – Alan Storm
    Jun 27, 2014 at 16:55

1 Answer 1


From a purely coding perspective, if you take a look at the getModelClassName method (a few calls down the stack from Mage::getModel)

public function getModelClassName($modelClass)
    $modelClass = trim($modelClass);
    if (strpos($modelClass, '/')===false) {
        return $modelClass;
    return $this->getGroupedClassName('model', $modelClass);

you'll see that if Magento doesn't see a / in the class alias, it assumes it's a full class name. However, if the getHelperClassName function

public function getHelperClassName($helperName)
    if (strpos($helperName, '/') === false) {
        $helperName .= '/data';
    return $this->getGroupedClassName('helper', $helperName);

If Magento doesn't see a / in the class alias, it assumes you're using the short form of


and adds a data to the end of the alias so the class resolves properly (catalog/data to Mage_Catalog_Model_Data).

This enables the short form helpers, but makes it impossible for Magento to tell the difference between a short form helper alias and a long form class name.

The ultimate "why" of this is probably hard to pin down — that the full class name instantiation works like that at all may just be a side effect of protective coding practices from one developer that were incompatible with another developer's desire for each module to have a "main" helper class. It also might be a single overworked developer making quick decisions as they go. There's probably lesson in project management and systems development in there somewhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.