On Tue, 14 Sep 2010 23:09:02 -0700, Stas Malyshev <smalys...@sugarcrm.com> wrote: > Hi! > >> class User { >> >> [NotNull] >> [Integer] >> public $id; >> >> [NotNull] >> [Regexp('/[a-z]*/i')] >> [MinLength(2)] >> [MaxLength(255)] >> public $name; >> >> [NotNull] >> [Zipcode] >> public $zipcode; >> } > > I'm not sure I understand - why can't you use normal data structure > to keep this information? Why it has to be in weird syntax with []s > that has to be accessed through reflection? >
- Annotations are like enum fields, or a function headers. You can only specify these values defined by the annotation. In normal data structures like arrays you can define what you will. - The meta information is defined on top of the property to which this information belongs. - To use this information by the validator you must make this information public in the object model. This can be more work, or the informations should not be accessible through the object. - When I look at the code I can promptly see what validation rules are used for this property. - Metadata is a part of the property, method or class. This information should not be described contextless. There are other examples in which the information should be described in context of the method, class or whatever. When using dependency injection as example. class Controller { [Inject] public function setRouter(Router $router) { } } The dependency injection container must know the method on which the router should be injected into the controller. Sure this information can be defined anywhere in the class or a config file. But the config file need also parsing time. And the information is quoted out of context. Can you really not see the elegancy and the advantage for the users? >> powerful frameworks which can used by a great range of developers >> without learning a new syntax for it. Pleas do not argue about thy >> syntax of the annotation because this isn't final. > > Whatever syntax it is, it is definitely new. > -- > Stanislav Malyshev, Software Architect > SugarCRM: http://www.sugarcrm.com/ > (408)454-6900 ext. 227 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php