Created
June 4, 2012 08:18
-
-
Save simonjodet/2867181 to your computer and use it in GitHub Desktop.
PHP anonymous class
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 | |
/** | |
* This is an helper class to quickly create anonymous classes | |
* Usage: | |
* $shellWrapper = new Anonymous(); | |
* $shellWrapper->exec = function($command) use($shellWrapper) | |
* { | |
* return exec($command); | |
* }; | |
* $shellWrapper->exec('ls -la .'); | |
*/ | |
class Anonymous | |
{ | |
function __call($name, $arguments) | |
{ | |
if (isset($this->$name) && $this->$name instanceof \Closure) | |
{ | |
return call_user_func_array($this->$name, $arguments); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment