Created
November 1, 2012 21:29
-
-
Save jankuca/3996709 to your computer and use it in GitHub Desktop.
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
$a = function () { | |
echo 'x'; | |
}; | |
$a(); |
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
$x = 4; | |
$a = function () { | |
echo $x; // x is not defined | |
}; | |
$a(); |
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
$x = 4; | |
$b = function () use ($x) { | |
echo $x; | |
}; | |
$b(); |
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
$a = new stdClass(); | |
$a->b = function () { | |
echo 'x'; | |
}; | |
$a->b(); // no such method 'b' |
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
$a = new stdClass(); | |
$a->b = function () { | |
echo 'x'; | |
}; | |
call_user_func($a->b); // no such method 'b' |
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
class A { | |
public function b() { | |
return function () { | |
$this->c(); // this cannot be used inside a closure | |
}; | |
} | |
public function c() { | |
}; | |
} | |
$a = new A(); | |
$a->b(); |
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
class A { | |
public function b() { | |
$self = $this; | |
return function () use ($self) { | |
$self->c(); | |
$self->d(); // call to a protected class from outside the object | |
}; | |
} | |
public function c() { | |
}; | |
protected function d() { | |
}; | |
} | |
$a = new A(); | |
$a->b(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment