Skip to content

Instantly share code, notes, and snippets.

@blar
Created September 24, 2012 20:30
Show Gist options
  • Select an option

  • Save blar/3778175 to your computer and use it in GitHub Desktop.

Select an option

Save blar/3778175 to your computer and use it in GitHub Desktop.
<?php
$user = function($name) {
$me = array(
'name' => NULL,
'init' => function($name) use(&$me) {
$me['name'] = $name;
return $me;
},
'whoami' => function() use(&$me) {
return $me['name'];
}
);
return $me['init']($name);
};
$foo = $user('bar');
$name = $foo['whoami']();
var_dump($name);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment