2

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?

2
  • 1
    I am not familiar with Magento but have you looked at the source code? Commented Nov 18, 2011 at 10:09
  • The source code is too big and the folder structure of Magento is too complicated. So I can't. :( Commented Nov 18, 2011 at 10:15

2 Answers 2

5

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 __call method in your class, The __call method 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_Object class see diagram and the magic methods like __get, __set and __call are defined here in the Varien_Object class and will be used by the classes which are inherited by Varien_Object class. You can find this class here /magento_installation_diretctory/lib/Varien/Object.php.

view the source code of Varien_Object class.

Sign up to request clarification or add additional context in comments.

2 Comments

Can you tell me the name of file where Magento call getName() or getSKU() functions?
@munjal: Ok, added more details.
1

probably by using __call

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.