Created
February 26, 2016 13:48
-
-
Save ushiboy/49d919ca79f3dfd24744 to your computer and use it in GitHub Desktop.
Closure::bindTo warning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Hoge | |
{ | |
static function foo() | |
{ | |
return function() { | |
echo "test"; | |
}; | |
} | |
function bar() | |
{ | |
return function() { | |
echo "test2"; | |
}; | |
} | |
} | |
class Caller | |
{ | |
function call(callable $fn) | |
{ | |
// http://php.net/manual/en/closure.bindto.php | |
$c = $fn->bindTo($this); | |
$c(); | |
} | |
} | |
(new Caller())->call(Hoge::foo()); // 5.5 & 5.6 => NG, 7.0 => OK | |
(new Caller())->call((new Hoge())->bar()); // 5.5 & 5.6 & 7.0 => OK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment