4

In the below code what does the :: operator mean or do?

<?php $_helper = Mage::helper('catalog/category') ?>

Also what does the helper do exactly?

2 Answers 2

6

In terms of PHP :: is a Scope Resolution Operator. Used to access static elements of a Class.

In Magento, Mage::helper(), here helper() is a STATIC function listed in Mage.php file, like public static function helper($name).

From your exampe, Mage::helper('catalog/category'), this will return an Object of Mage_Catalog_Helper_Category helper. Check this line in helper function definition, $helperClass = self::getConfig()->getHelperClassName($name);

1
  • 5
    The double colon - scope resolution operator is also known as a Paamayim Nekudotayim. Although in 10 years in software development, I'm yet to encounter someone who can pronounce it, or spell it without looking it up, myself included. :)
    – i-CONICA
    Commented Jun 28, 2016 at 11:03
5

in PHP, :: specify scope resolution operator,

Its native php functionality for getting static function,variable from php file.

Mage::helper() means static helper function is defined inside `app/Mage.php file`.

first get helper function from Mage.php file,

 public static function helper($name)
    {
        $registryKey = '_helper/' . $name;
        if (!self::registry($registryKey)) {
            $helperClass = self::getConfig()->getHelperClassName($name);
            self::register($registryKey, new $helperClass);
        }
        return self::registry($registryKey);
    }

Helper function is called first from mage.php file when you can use any helper in module. They define module full path to access it.

You can get more info about this using link, Scope resolution operator

$_helper = Mage::helper('catalog/category')

Now $_helper variable get access to all function of Mage_Catalog_Helper_Category.php file

If you want to fetch getStoreCategories() functions from above file, you can simple call $_helper->getStoreCategories(false,false,true) and return store category object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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