destructor_and_globals.phpt 836 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. --TEST--
  2. ZE2 accessing globals from destructor in shutdown
  3. --FILE--
  4. <?php
  5. $test_cnt = 0;
  6. $test_num = 0;
  7. function Show() {
  8. global $test_cnt;
  9. echo "Count: $test_cnt\n";
  10. }
  11. class counter {
  12. protected $id;
  13. public function __construct() {
  14. global $test_cnt, $test_num;
  15. $test_cnt++;
  16. $this->id = $test_num++;
  17. }
  18. public function Show() {
  19. echo 'Id: '.$this->id."\n";
  20. }
  21. // try protected here
  22. public function __destruct() {
  23. global $test_cnt;
  24. $test_cnt--;
  25. }
  26. static public function destroy(&$obj) {
  27. $obj = NULL;
  28. }
  29. }
  30. Show();
  31. $obj1 = new counter;
  32. $obj1->Show();
  33. Show();
  34. $obj2 = new counter;
  35. $obj2->Show();
  36. Show();
  37. counter::destroy($obj1);
  38. Show();
  39. // or uncomment this line and it works
  40. //counter::destroy($obj2);
  41. echo "Done\n";
  42. ?>
  43. --EXPECT--
  44. Count: 0
  45. Id: 0
  46. Count: 1
  47. Id: 1
  48. Count: 2
  49. Count: 1
  50. Done