On Tue, Feb 24, 2015 at 2:25 PM, Stanislav Malyshev <smalys...@gmail.com> wrote: > Hi! > >> I like the idea of having anonymous classes, it is very helpful during >> development to just try something out without having the burden of >> creating a new file and a complete class including namespace and use >> declarations, etc. > > I think this particular argument is a bit backwards. In PHP, you > certainly don't need to create new file to just introduce a new class. > If you're working within a framework that makes it a problem, time to > think if the framework you're using is fit for your purposes. But PHP > certainly does not impose such limitations. > >> A great feature of anonymous classes in Java is their ability to access >> the private/protected properties of the object they are defined in, >> similar to what Closures do in PHP. The thing is, in Java if you access >> a variable (without this.), it may be of the current scope, a member of >> the current class or a member of the class where the anonymous class was >> defined in. In PHP, you have to use $this-> to access class members of > > That may be a problem to implement, exactly since you need $this in PHP. > >> Second thing is serialization. PHP closures can not be serialized, does >> the same apply for anonymous classes? It would be really nice if such > > Serializing is not a problem, unserializing would be - as there may be > no class for this object to instantiate. > > -- > Stas Malyshev > smalys...@gmail.com > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >
If anyone wants to have a play with anonymous classes, our friends over at 3v4l.org have made this incredibly easy to do: http://3v4l.org/elh6I/rfc#rfc-anonymous_classes Awesome. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php