On 24 September 2013 14:51, Nicolas Grekas <nicolas.grekas+...@gmail.com>wrote:
> What about allowing a "use" statement on these methods? > > $someFoo = "bar"; > > $object = new class{ > function method() use ($someFoo) { return $someFoo;} > } > > $object->method(); // "bar"; > I think the idea of anonymous classes is very useful. a use case that I recently encountered, is to override a specific method in a class. So instead of creating a new class that extends the original class, you can just use an anonymous class and override the methods that you want. E.G. You can to the following: use Symfony\Component\Process\Process; $process = new class extends Process { public function start() { /* ... */ } }; instead of the following: namespace My\Namespace\Process; use Symfony\Component\Process\Process as Base; class Process extends Base { public function start() { /* ... */ } } $process = new \My\Namespace\Process\Process;