Created
December 2, 2015 22:16
-
-
Save lstrojny/d7b10c51be6bdf8d3d45 to your computer and use it in GitHub Desktop.
Higher order capture
This file contains 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 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