Skip to content

Instantly share code, notes, and snippets.

@rikmeijer
Created March 27, 2019 19:37
Show Gist options
  • Save rikmeijer/68619febbafb7c4b5c6a589ea7936b26 to your computer and use it in GitHub Desktop.
Save rikmeijer/68619febbafb7c4b5c6a589ea7936b26 to your computer and use it in GitHub Desktop.
function to create a recursable closure
<?php
function rf(Closure $f) {
return new class($f) {
private $f;
public function __construct(Closure $f)
{
$this->f = $f;
}
public function __invoke() {
return ($this->f->bindTo($this))(...func_get_args());
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment