Lazare Inepologlou <linep...@gmail.com> schrieb: > I use anonymous classes very frequently in Java and in C#, and I would say > that they are quite useful. However the examples given in the RFC are > really bad ones. Why on earth would you need a constructor for an anonymous > class? Anonymous classes are used to implement quickly some interface. > Frankly, constructors are not part of any interface. Besides a constructor > is totally useless in an anonymous class as it will never be called after > the object is created.
The need for anonymous classes in Java mostly comes from implementing interfaces on demand due to the lack of lamdas and the requirements of a strongly typed language. PHP has lambdas and it doesn't require you to match typing. Therefore I think the preferred way for most of the use cases is to use a lambda or if a bigger implementation is necessary, to give it a name. Due to namespacing you don't pollute the global scope anyway. Therefore I don't see much reason left as to why add anonymous classes and I really have a hard time finding a use case, except for trying to write PHP as you would write Java (which most likely is a bad idea). - David -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php