language013.phpt 420 B

12345678910111213141516171819202122232425262728293031323334353637
  1. --TEST--
  2. Statics work like expected for language-based copy'n'paste. No link between methods from the same trait.
  3. --FILE--
  4. <?php
  5. error_reporting(E_ALL);
  6. trait Counter {
  7. public function inc() {
  8. static $c = 0;
  9. $c = $c + 1;
  10. echo "$c\n";
  11. }
  12. }
  13. class C1 {
  14. use Counter;
  15. }
  16. class C2 {
  17. use Counter;
  18. }
  19. $o = new C1();
  20. $o->inc();
  21. $o->inc();
  22. $p = new C2();
  23. $p->inc();
  24. $p->inc();
  25. ?>
  26. --EXPECT--
  27. 1
  28. 2
  29. 1
  30. 2