Skip to content

Instantly share code, notes, and snippets.

@fkulakov
Last active November 5, 2019 12:57
Show Gist options
  • Save fkulakov/ca2b54c900f304a3409b93fdbc3149a4 to your computer and use it in GitHub Desktop.
Save fkulakov/ca2b54c900f304a3409b93fdbc3149a4 to your computer and use it in GitHub Desktop.
Pipe example
<?php declare(strict_types=1);
/**
* @param null $_
*
* @return object
*/
function pipe(&$_)
{
return new class($_)
{
private $_;
/**
* @param null $_
*/
public function __construct(&$_)
{
$this->_ = &$_;
}
/**
* @param string $name
* @param array $args
*
* @return self
*/
public function __call(string $name, array $args): self
{
$this->_ = $name(...$args);
return $this;
}
};
}
pipe($_)
->strtoupper('!rov nitup')
->strrev($_)
->var_dump($_);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment