Skip to content

Instantly share code, notes, and snippets.

@simonjodet
Created June 4, 2012 08:18
Show Gist options
  • Save simonjodet/2867181 to your computer and use it in GitHub Desktop.
Save simonjodet/2867181 to your computer and use it in GitHub Desktop.
PHP anonymous class
<?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