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?

Reply via email to