Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class struct {
- private $args;
- function __construct(array $args) {
- $this->args = $args;
- }
- function __invoke(callable $signature = NULL) : array {
- return $signature(...array_values($this->args));
- }
- }
- final class Dinosaur extends struct {
- function signature(int $legs) : array {
- return get_defined_vars();
- }
- }
- $two_legs = function(Dinosaur $dino) : Dinosaur {
- $trex = $dino([$dino, 'signature']);
- $trex['legs'] = 2;
- return new Dinosaur($trex);
- };
- var_dump($two_legs(new Dinosaur([0])));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement