Pregunta

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

¿Fue útil?

Solución

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top