3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php abstract class Mother { /** @var array */ private static $inMemoryCache = []; public function testMethod($param) { $cacheKey = '_'.$param; if (!isset(self::$inMemoryCache[$cacheKey])) { echo PHP_EOL, 'compute result', PHP_EOL; self::$inMemoryCache[$cacheKey] = $param * 2; } return self::$inMemoryCache[$cacheKey]; } } final class Daughter extends Mother { } final class Son extends Mother { } $d = new Daughter(); $s = new Son(); $d->testMethod(1); $d->testMethod(1); $s->testMethod(1); $s->testMethod(1);
Output for 5.4.0 - 5.6.38, hhvm-3.10.1 - 3.22.0, 7.0.0 - 7.3.0rc3
compute result
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/j03Dp on line 5
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/j03Dp on line 5
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_CLASS in /in/j03Dp on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_CLASS in /in/j03Dp on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/j03Dp on line 2
Process exited with code 255.