Aer Interpreter Source
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
645 B

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. final class Test {
  2. private int $value;
  3. private void __construct() {
  4. print('Constructor called.' + "\n");
  5. }
  6. private void __destruct() {
  7. print('Destructor called.' + "\n");
  8. }
  9. /* This is singleton */
  10. public static object getInstance() {
  11. static object $instance;
  12. if(!$instance) {
  13. $instance = new Test();
  14. }
  15. return $instance;
  16. }
  17. public int get() {
  18. return $this->value;
  19. }
  20. public int set(int $value = 0) {
  21. $this->value = $value;
  22. }
  23. }
  24. final class Program {
  25. public void main() {
  26. object $testA = Test::getInstance();
  27. $testA->set(5);
  28. object $testB = Test::getInstance();
  29. var_dump($testB->get());
  30. }
  31. } /* class */