Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. <?php
  2.  
  3. class clonable
  4. {
  5. public function __construct(...$args)
  6. {
  7. $this->args = func_get_args();
  8. }
  9.  
  10. public function __clone()
  11. {
  12. return new self(...$this->args);
  13. }
  14. }
  15.  
  16. class a extends clonable
  17. {
  18. public function __construct($a, $b)
  19. {
  20. parent::__construct($a, $b);
  21. $this->a = $a;
  22. $this->b = $b;
  23. }
  24. }
  25.  
  26. $a1 = new a(1, 2);
  27. $a2 = clone $a1;
  28. $a2->b = 3;
  29.  
  30. var_dump($a1, $a2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement