You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
652 B

23 years ago
  1. --TEST--
  2. ZE2 singleton
  3. --SKIPIF--
  4. <?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
  5. --FILE--
  6. <?php
  7. class Counter {
  8. private $counter = 0;
  9. function increment_and_print() {
  10. echo ++$this->counter;
  11. echo "\n";
  12. }
  13. }
  14. class SingletonCounter {
  15. private static $m_instance = NULL;
  16. static function Instance() {
  17. if (self::$m_instance == NULL) {
  18. self::$m_instance = new Counter();
  19. }
  20. return self::$m_instance;
  21. }
  22. }
  23. SingletonCounter::Instance()->increment_and_print();
  24. SingletonCounter::Instance()->increment_and_print();
  25. SingletonCounter::Instance()->increment_and_print();
  26. ?>
  27. --EXPECT--
  28. 1
  29. 2
  30. 3