Skip to content

Instantly share code, notes, and snippets.

@bcremer
Created September 29, 2015 20:18
Show Gist options
  • Save bcremer/3e42c771a061ff4970b8 to your computer and use it in GitHub Desktop.
Save bcremer/3e42c771a061ff4970b8 to your computer and use it in GitHub Desktop.
class LazyString
{
/**
* @var callable
*/
private $callee;
/**
* @param callable $callee
*/
public function __construct(callable $callee)
{
$this->callee = $callee;
}
public function __toString()
{
return call_user_func($this->callee);
}
}
$lazyString = new LazyString(function () {
return some_heavy_string_function();
});
echo $lazyString;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment