fork download
  1. <?php
  2.  
  3. define('SOMETHING', true);
  4.  
  5. class ExampleClass {
  6. private static $var = array("hi");
  7.  
  8. public static function exampleFunction() {
  9. if(SOMETHING) {
  10. self::$var[] = "hello";
  11. }
  12. } //I print out this change and it works, containing both hi and hello
  13.  
  14. public static function getVar() {
  15. return self::$var;
  16. } //this does not return the updated array, only the original with hi
  17.  
  18. }
  19.  
  20. // add hello to the array ExampleClass::$var
  21. ExampleClass::exampleFunction();
  22.  
  23. // get $var
  24. $var = ExampleClass::getVar();
  25.  
  26. var_dump($var);
Success #stdin #stdout 0.02s 24448KB
stdin
Standard input is empty
stdout
array(2) {
  [0]=>
  string(2) "hi"
  [1]=>
  string(5) "hello"
}