fork download
  1. <?php
  2.  
  3. class Foo {
  4. private static $bar = NULL;
  5.  
  6. public static function getBar() {
  7. if (self::$bar == NULL)
  8. {
  9. echo "Inicializuji \$bar\n";
  10. self::$bar = 42;
  11. }
  12. else
  13. {
  14. echo "Vracím dříve inicializovaný \$bar\n";
  15. }
  16. return self::$bar;
  17. }
  18. }
  19.  
  20. Foo::getBar();
  21. Foo::getBar();
  22. Foo::getBar();
  23. Foo::getBar();
  24.  
Success #stdin #stdout 0.01s 23704KB
stdin
Standard input is empty
stdout
Inicializuji $bar
Vracím dříve inicializovaný $bar
Vracím dříve inicializovaný $bar
Vracím dříve inicializovaný $bar