[TYPO3-mvc] Magic Getters and Setters for AbstractDomainObject

Aimo Kuenkel mail at aimo.cc
Thu Oct 24 18:05:03 CEST 2013


Hi,

I can only encourage people to use snippets in sublimetext or autocompletion for getters/setters in other IDEs. Noone should waste more than a bunch of seconds to create a property with the respective functions.

Also, I think the "API" of an Object (getters/setters) should be obvious by looking at the class. Not so with Repositories, there it's much less dangerous to use methods not intended by the author as I see it.

Regarding your note on casting in setters - why would you not cast incoming values in a getter to ensure correct types?
Could you explain the problem with the property mapper using reflection?

Thanks,

Aimo Künkel


-----Ursprüngliche Nachricht-----
Von: typo3-project-typo3v4mvc-bounces at lists.typo3.org [mailto:typo3-project-typo3v4mvc-bounces at lists.typo3.org] Im Auftrag von Christian Kuhn
Gesendet: Donnerstag, 24. Oktober 2013 17:26
An: typo3-project-typo3v4mvc at lists.typo3.org
Betreff: Re: [TYPO3-mvc] Magic Getters and Setters for AbstractDomainObject

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
_______________________________________________
TYPO3-project-typo3v4mvc mailing list
TYPO3-project-typo3v4mvc at lists.typo3.org
http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc


More information about the TYPO3-project-typo3v4mvc mailing list