On 09/25/2013 09:59 AM, Terence Copestake wrote:
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?


1) Anonymous classes in PHP would support a constructor, so I don't see the need for use to be utilized here, it would just clutter declarations and the patch.

2) Again, constructors can be used, and is less confusing than introducing a new variable, but I'm open to persuasion if the idea is liked in general ...

Well, it's likely possible to introduce a shared kind of scope, but I don't really think it's necessary, for the same reasons as 1) and 2).

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

Reply via email to