Last active
November 5, 2019 12:57
-
-
Save fkulakov/ca2b54c900f304a3409b93fdbc3149a4 to your computer and use it in GitHub Desktop.
Pipe example
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 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