[TYPO3-mvc] Magic Getters and Setters for AbstractDomainObject

Christian Kuhn lolli at schwarzbu.ch
Thu Oct 24 17:25:42 CEST 2013


Hey,

On 10/17/2013 03:37 PM, Philipp wrote:
> What exactly is the reason why there are no magic getters and setters in
> the AbstractDomainObject Class?
> Sometimes i really get tired from writing all those simple methods.
>
> Could easily be realized using the reflection.... 90% of alle getters
> are the same and close to 100% of common setters.
>
> Would make the coding a bit faster....

Imho, the basic need for getters and setters is mostly a PHP language 
restriction, since you can not do eg. casting on a property like this:

public integer $aNumber;

I would love to see that in PHP, it would be much smarter than a setter 
method and a getter that does the casting. BTW: Do not cast the other 
way round in extbase: You should always cast in getters, since the 
property mapper uses reflection to set properties and does not call 
setter methods (a fact I always disliked).


For the "no magic" question itself, I found a reference in the Flow 
documentation [1]:

"Of course we considered magic getters and setters. But then, how do you 
restrict read or write access to single properties? Furthermore, magic 
methods are notably slower and you loose the benefit of your IDE's 
autocompletion feature. Fortunately IDEs like Netbeans or Zend Studio 
provide functions to create getters and setters automatically."


[1] 
http://docs.typo3.org/flow/TYPO3FlowDocumentation/stable/TheDefinitiveGuide/PartII/Modeling.html


Regards
Christian


More information about the TYPO3-project-typo3v4mvc mailing list