3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class A { public static function foo() { static $arr = array(); $arr[] = 2; return $arr; } } class C extends A { } printf("%s\n", json_encode(A::foo())); printf("%s\n", json_encode(A::foo())); printf("%s\n", json_encode(C::foo())); eval('class B extends A{}'); printf("\nIt would be intuitive for B::foo() to be [2], but the real value is below\n"); printf("%s\n", json_encode(B::foo()));
based on vZCus
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.2.6
[2] [2,2] [2] It would be intuitive for B::foo() to be [2], but the real value is below [2,2,2]
Output for hhvm-3.12.14 - 3.17.3
[2] [2,2] [2] It would be intuitive for B::foo() to be [2], but the real value is below [2]