Re: new feature -> with()

From: Date: Wed, 10 Oct 2007 16:08:52 +0000
Subject: Re: new feature -> with()
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-32726@lists.php.net to get a copy of this message
--------------------------- $class=new class; with($class) {
    do_something();
    do_more();
    do();
}
What more value does this hold over implementing fluent interfaces which are already possible? Assuming class Foo { public function doSomething() { /**code**/ return $this; } public function doMore() { /**code**/ return $this; } public function doDo() { /**code**/ return $this; } } You can do this: $bar = new Foo() $bar->doSomething()->doMore()->doDo(); or, if you want exceptional fallthrough: try { $bar->doSomething()
      ->doMore()
      ->doDo();
} catch (Exception $e) { ... } -ralph

« previous php.internals (#32726) next »