On Thu, Sep 26, 2013 at 5:59 PM, Joe Watkins <krak...@php.net> wrote:
> Ok, I included just about all the information on use cases that is obvious
> or has been discussed, so I think we got use cases covered now, right ??
>
> See a good one yet ??
>
>
> Cheers
> Joe

Wondering about scoping. Yes, anonymous classes can have their own
constructor, but if we're adding syntactic sugar why not make it
possible to use from the scope they're created in?

See this example adapted from a Stack Overflow question about how it
works in Java [1]:

(not sure how you the "use" syntax should look like)

public function doStuff($userId) {
    $this->doOtherStuff($userId, new class implements SomeInterface {
        public function onSuccess() {
             echo $userId;
        }
    });
}

vs

public function doStuff($userId) {
    $this->doOtherStuff($userId, new class implements SomeInterface {
        private $userId;
        public function __construct($userId) {
            $this->userId = $userId;
        }
        public function onSuccess() {
             echo $this->userId;
        }
    });
}

[1] 
http://stackoverflow.com/questions/3251018/java-anonymous-inner-class-using-a-local-variable

Cheers,

Alexander

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

Reply via email to