fork(2) download
  1. <?php
  2. class A {
  3. public $b;
  4.  
  5. public function __construct(B $b) {
  6. $this->b = $b;
  7. }
  8. }
  9.  
  10. class B {}
  11.  
  12. class C extends A {
  13. public function __clone() {
  14. $this->b = clone $this->b;
  15. }
  16. }
  17.  
  18. $a = new A(new B);
  19. $aa = clone $a;
  20. $b = $a;
  21. $c = new C(new B);
  22. $cc = clone $c;
  23. echo "CĂ“PIA\n";
  24. var_dump($a === $b);
  25. var_dump($a->b === $b->b);
  26. echo "SEM __CLONE\n";
  27. var_dump($a === $aa);
  28. var_dump($a->b === $aa->b);
  29. echo "COM __CLONE\n";
  30. var_dump($c === $cc);
  31. var_dump($c->b === $cc->b);
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
CÓPIA
bool(true)
bool(true)
SEM __CLONE
bool(false)
bool(true)
COM __CLONE
bool(false)
bool(false)