3

I understand why and how Magento uses the secondary/pseudo constructor e.g. the constructor that begins with a single underscore.

Is there a specific name for this method:

pseudo constructor secondary constructor etc.

4

I've never seen anything official on this over the years — I vacillate between calling it Magento's pseudo-constructor or Magento's internal-constructor. Looking at the method definition

#File: lib/Varien/Object.php
/**
 * Internal constructor not depended on params. Can be used for object initialization
 */
protected function _construct()
{
}

it looks like Internal constructor is the closest thing we have to a proper name.

| improve this answer | |
2

Syntactically is it a method. With this interpretation the name is badly chosen :-)

I don't think there is something like a "pseudo constructor", "second constructor", etc.

A constructor is a method which is called AUTOMATICALLY, and there is onle one which is called automatically in php: __construct.

And to be honest: I don't understand why and how magento uses this concept, please explain :-)

| improve this answer | |
  • 1
    The why is to have a place for constructor like behavior without needing to worry about parameters into the constructor. This way people writing classes that inherit from Varien_Object can have a constructor for initialization without worrying about what parameters the parent class used (as they'd have to if they redefined the real constructor) – Alan Storm Dec 9 '13 at 22:49
0

There is a stackoverflow question already out there with some more details on both Alan and Fabians answer:

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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