Last active
December 18, 2015 05:18
-
-
Save AV4TAr/5731236 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Pepe | |
| { | |
| protected $loaded; | |
| public function __construct() | |
| { | |
| $that = $this; | |
| $this->loaded = function () use ($that) { | |
| $that->load(); | |
| }; | |
| } | |
| public function haceAlgo(){ | |
| $this->loaded && $this->loaded->__invoke(); | |
| } | |
| public function load() | |
| { | |
| //... | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Explicación de porqué no usa $this->loaded();
http://stackoverflow.com/questions/7067536/how-to-call-a-closure-that-is-a-class-variable
Código sacado de:
https://github.com/AV4TAr/BjyAuthorize/blob/master/src/BjyAuthorize/Service/Authorize.php#L158