Re: RFC: Anonymous Classes
| From: | Terence Copestake | Date: | Wed, 25 Sep 2013 08:59:10 +0000 |
| Subject: | Re: RFC: Anonymous Classes | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-69334@lists.php.net to get a copy of this message | ||
I'm growing to like the idea myself. It may create new opportunities for
bad practices, but I don't think it's the concern of internals to police
how people may or may not use a feature. There are also I think a few
things that would need to be addressed before this would be ready for the
real world. For example:
1) As hinted at previously, the "use" statement. Doing this per-method as
suggested would be less ambiguous than applying to the whole class - and
would also prevent pollution.
2) Transparency between an anonymous class and the class in which it is
defined (if any). One thing I found very restrictive about closures back in
5.3 was the lack of $this support. I can imagine that missing functionality
being similarly restrictive for these new anonymous classes. Obviously
$this itself will be reserved for use by the anonymous class, which means
there would need to be an alternative. Passing in a variable is one thing,
but as it stands the anon class would then only have public access.
Something like $class with similar behaviour to $this could be an option.
In Java I believe anonymous classes have the same scope as the method in
which they're defined. Would something like this or similar be feasible and
permissible in PHP?