Skip to content

Instantly share code, notes, and snippets.

@pawlik
Last active August 29, 2015 14:12
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 pawlik/5189e75a4ccbd52fa589 to your computer and use it in GitHub Desktop.
Save pawlik/5189e75a4ccbd52fa589 to your computer and use it in GitHub Desktop.
is ruby like tap possible in php even in ?
<?php
class Tappable {
private $whatever = null;
public function __construct($whatever) {
$this->whatever = $whatever;
}
public function tap(callable $callback) {
$callback($this->whatever);
return $this->whatever;
}
}
$callback = function($h){
echo "do sth with $h\n";
echo "do sth else with $h\n";
};
// anyway you have to pollute your namespace here:
$x = new Tappable("123");
$x->tap($callback);
// because this will not work in php <= 5.6.4
(new Tappable("hakunamatata")).tap($callback);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment