Understanding Magento Core Override and reference

As a practice in Magento Development, all custom code/modification need to be made via local or community by overriding convention.

However sometime, you can’t override some Magento core classes and there is no available document explaining this problem clearly. I have decided to get deep into this issue and I found that only classes that are instantiated using Mage::getModel() can be overloaded.

Therefore, all classes instantiated directly with new operator are not possible to override. For example you can’t rewrite “Mage_Core_Model_App”, it is initialed on line 712 in Mage.php
self::$_app = new Mage_Core_Model_App();

Here is the short list of such classes
Mage_Core_Model_App
Varien_Event_Collection
Mage_Core_Model_Config
Mage_Core_Exception
Varien_Object_Cache

Please notice about difference between Overriden and Inheritance. “Overriden” is referred to cases when you want to modify a behavior of classes when they are called and used somewhere else in the system. While “Inheritance” meaning you want to reuse some methods from existing classes and just need to extend them for your modules. Then you can do it as usually.

Keyword : Magento, Magento Overriden, Magento Programming Practice, Magento Reference, Magento Override Problem

Comments

Leave a Reply

Your email address will not be published.

nineteen − 4 =

Security Code: