fork download
  1. <?php
  2. class base {
  3. function calc() {
  4. static $foo = 0;
  5. $foo++;
  6. return $foo;
  7. }
  8. }
  9.  
  10. class one extends base {
  11. function e() {
  12. echo "one:".$this->calc().PHP_EOL;
  13. }
  14. }
  15. class two extends base {
  16. function p() {
  17. echo "two:".$this->calc().PHP_EOL;
  18. }
  19. }
  20. $x = new one();
  21. $y = new two();
  22. $x_repeat = new one();
  23.  
  24. $x->e();
  25. $y->p();
  26. $x->e();
  27. $x_repeat->e();
  28. $x->e();
  29. $x_repeat->e();
  30. $y->p();
  31. // your code goes here
Success #stdin #stdout 0.02s 25968KB
stdin
Standard input is empty
stdout
one:1
two:1
one:2
one:3
one:4
one:5
two:2