Can anyone tell me how Magento creates dynamic functions? For example for product info, we call:
$product = Mage::getModel('catalog/product')->load(29);
$product->getData() return all the data in array format. But we can fetch the same information from the individual functions like:
$product->getSkuId()
$product->getProdId()
$product->getName()
Can anyone tell me that how Magento creates these dynamic functions?
Magento is using __call magic method. When you try to call a method which is really does not exists with that class and if you have defined
__callmethod in your class, The__callmethod is called and Magento take the name of actual requested method and call the another method which handles this request to fetch particular thing for you.EDIT
All the Model classes are inherited from the
Varien_Objectclass see diagram and the magic methods like__get,__setand__callare defined here in theVarien_Objectclass and will be used by the classes which are inherited byVarien_Objectclass. You can find this class here/magento_installation_diretctory/lib/Varien/Object.php.view the source code of Varien_Object class.