Hi Phil,

Am 24.02.2015 um 14:52 schrieb Philip Sturgeon:
> https://wiki.php.net/rfc/anonymous_classes

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.

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
the anonymous class but there is some $outer-> or similar variable
missing for the access. You can as a work around pass all members by
reference via the constructor, but that is really not nice.

In addition, if you define an anonymous class inside a "real" class and
pass another instance of the outer class, the anonymous class can still
access the private/protected methods imho. Any thoughts how to handle
this or should we just ignore it for now?

Second thing is serialization. PHP closures can not be serialized, does
the same apply for anonymous classes? It would be really nice if such
anonymous classes could e.g. send via a command bus or something to be
executed on another host.

Thanks
Dennis

P.s.: there is a footnote in the RFC that does not belong there is think

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to