Edit report at https://bugs.php.net/bug.php?id=64761&edit=1
ID: 64761 Comment by: wanwizard at fuelphp dot com Reported by: netmosfera at gmail dot com Summary: rebinding of closures doesn't work when they are declared in a static method Status: Wont fix Type: Bug Package: *General Issues Operating System: any PHP Version: 5.5.0beta4 Block user comment: N Private report: N New Comment: To illustrate, I now have to this to get it to work: class Dummy { public function __construct($event, $object) { // setup a shutdown event for writing cookies $event->on('shutdown', function($event) { $this->process(); }, $object); } } new Dummy($event, $instance); which does exactly the same, but now the closure is defined in an object context. Which is insane... Previous Comments: ------------------------------------------------------------------------ [2013-08-09 09:02:11] wanwizard at fuelphp dot com I understand the issue of scope here, but imho the location of where the closure is not relevant. You get the same error when you do: public static function somemethod() { // construct the a new object $instance = static::factory(); // get the current event object $event = \Event::getInstance(); // setup a shutdown event $event->on('shutdown', function($event) { $this->process(); }, $instance); } where the "on" method is trying to bind $instance (which is an object, so there should be no issue, $this is defined), but fails with this same error. ------------------------------------------------------------------------ [2013-05-04 05:07:03] larue...@php.net as I saw, it's by design, and there are some test scripts about that: https://github.com/php/php-src/blame/master/Zend/zend_closures.c#L499 btw, why should I trun to ircmaxell? he is the author of this? ------------------------------------------------------------------------ [2013-05-03 23:52:51] hanskrentel at yahoo dot de @laruence: This is not by design. Please take a second look on this report. Thank you. You probably want to summon ircmaxell for help. ------------------------------------------------------------------------ [2013-05-03 23:44:25] netmosfera at gmail dot com makes no sense to me! also in the global scope $this isn't available, but rebind does work! ------------------------------------------------------------------------ [2013-05-03 15:28:02] larue...@php.net it's by design. if you create a closure within a "scope", then the function actually is a "METHOD", thus must be bound to current object(this) or static. for your example, since the closure is create in a static function blah, which makes no "this" avaliable while creating closure, then the closure is created as static .. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=64761 -- Edit this bug report at https://bugs.php.net/bug.php?id=64761&edit=1