Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. <?php
  2.  
  3. class struct {
  4. private $args;
  5. function __construct(array $args) {
  6. $this->args = $args;
  7. }
  8. function __invoke(callable $signature = NULL) : array {
  9. return $signature(...array_values($this->args));
  10. }
  11. }
  12.  
  13. final class Dinosaur extends struct {
  14. function signature(int $legs) : array {
  15. return get_defined_vars();
  16. }
  17. }
  18.  
  19. $two_legs = function(Dinosaur $dino) : Dinosaur {
  20. $trex = $dino([$dino, 'signature']);
  21. $trex['legs'] = 2;
  22. return new Dinosaur($trex);
  23. };
  24.  
  25. var_dump($two_legs(new Dinosaur([0])));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement