Re: [RFC] Anonymous Classes
| From: | Stanislav Malyshev | Date: | Tue, 24 Feb 2015 19:25:54 +0000 |
| Subject: | Re: [RFC] Anonymous Classes | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-83688@lists.php.net to get a copy of this message | ||
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
smalyshev@gmail.com