Question

I've been trying to find some info on difference between instantiating form fields through static method and the new keyword. Can somebody tell me what are the practical implications, limitations, between new MyFormField and MyFormField::create() esp. with regards to SilverStripe

Was it helpful?

Solution

Using the create factory method would check for overloads (set via Object::useCustomClass()) and return an instance of the custom class in that case.

This method first for strong class overloads (singletons & DB interaction), then custom class overloads. If an overload is found, an instance of this is returned rather than the original class. To overload a class, use Object::useCustomClass()

So using the create method rather than instantiating the Object yourself would provide a possibility to overload the used Class without altering the code.

see
http://api.silverstripe.org/3.1/class-Object.html#_useCustomClass
http://api.silverstripe.org/3.1/class-Object.html#_create

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top