Skip to content

Instantly share code, notes, and snippets.

@ushiboy
Created February 26, 2016 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ushiboy/49d919ca79f3dfd24744 to your computer and use it in GitHub Desktop.
Save ushiboy/49d919ca79f3dfd24744 to your computer and use it in GitHub Desktop.
Closure::bindTo warning
<?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