Re: RFC: Anonymous Classes
| From: | Kristopher | Date: | Tue, 24 Sep 2013 12:30:07 +0000 |
| Subject: | Re: RFC: Anonymous Classes | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-69314@lists.php.net to get a copy of this message | ||
On Tue, Sep 24, 2013 at 8:25 AM, Terence Copestake <
terence.copestake@gmail.com> wrote:
> Playing devil's advocate here, could this feature make the language more
> expressive?
>
> Take for example an API where you'd typically wrap a method call in
> try/catch blocks to handle the various "outcomes" e.g. a user login, you'd
> maybe have a UserDisabled exception, a UserAlreadyLoggedIn exception, a
> UserPasswordIncorrect exception, etc.
>
> With the addition of this syntactic sugar, the method could instead accept
> an anonymous class with a onDisabled, onLoggedIn, onPasswordIncorrect
> methods.
>
> Perhaps it would also have a performance benefit over cascading through
> catch blocks? Though someone else would have to confirm that.
>
Why wouldn't you want this to a concrete, real class? I don't see the
benefit, in your example, of doing an anonymous class vs defining an actual
class and passing that in as the handler.