Chris Stockton a écrit :
Hello,
On Tue, Nov 17, 2009 at 2:59 AM, Mathieu Suen
<mathieu.s...@easyflirt.com> wrote:
Christian Seiler a écrit :
Hi,
since a few months have passed since the last discussion on this topic
and perhaps people had time to gather some experience with the current
closure implementation in PHP 5.3 I'd like to restart the debate on
$this in closures and object extension.
I believe that (D) wins my vote, and it convinces me twice. Once
because I believe it is the most intuitive for users (A), and twice
because I believe it is also the most useful (C) for users. In my
opinion It seems the most "PHP" way.
-Chris
(D) is quite inconstant:
$block = $foo->closur;
$foo->closur();
$block();
This would produce 2 different output.
For (C) here is my objection:
Suppose that we are in a MVC pattern.
In a controller on could do:
$model->onFailDo(function () {$this->reportError()});
$model->save();
In the model side:
public function onFailDo($block)
{
$this->signalFailure = $block
}
public function save()
{
//... Something wrong happen
return $this->signalFailure();
}
If you dynamically bind the $this you are obliged to treat the error
reporting in the model which is not a good idea. Even worst you can't
even catch up the error in the controller.
It also mean that the closure is getting tightly coupled with anyone who
is using it. And passing closure to different object is like spreading
dependency over all the system.
-- Mathieu Suen
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php