Skip to content

Instantly share code, notes, and snippets.

@lstrojny
Created December 2, 2015 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lstrojny/d7b10c51be6bdf8d3d45 to your computer and use it in GitHub Desktop.
Save lstrojny/d7b10c51be6bdf8d3d45 to your computer and use it in GitHub Desktop.
Higher order capture
<?php
class Connection
{
public function transactional(callable $callback)
{
$callback();
}
}
function capture(&$result, callable $callback) {
return function () use (&$result, $callback) {
$result = $callback();
};
}
$connection = new Connection();
$connection->transactional(capture($result, function() { return 'hello';}));
var_dump($result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment