Is there a reason why Magento has a _construct and a __construct method? Why does the additional _construct exist? Could anything achieved by having the extra _construct method not be achieved by just calling the parent constructor in the child class?
Is there a reason why Magento has a _construct and a __construct method? Why
Share
Best answer I can find: http://www.magentocommerce.com/boards/viewthread/76027/#t282659
Basically, the root-level class (from which all other classes inherit) implements
__construct, which PHP calls automatically whenever a class is constructed. Right now, this root-level class simply calls_construct, which contains the actual code.Say you have this set-up:
PHP doesn’t automatically call the parent class constructors, so
doSomethingReallyImportantnever gets called. You could require that subclass constructors callparent::__construct(), but that’s easy to forget. So Magento has subclasses override_construct:PHP doesn’t detect a constructor in
SubClass, so it callsBaseClass‘s constructor. This allowsBaseClasstodoSomethingReallyImportantbefore calling SubClass’s overridden_construct.