3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php abstract class Mother { /** @var array */ private static $inMemoryCache = array(); 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);
based on j03Dp
Output for 5.0.2 - 5.6.38, hhvm-3.10.1 - 3.22.0, 7.0.0 - 7.3.0rc3
compute result
Output for 5.0.0 - 5.0.1
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/d4VpL on line 12 PHP_EOLcompute result Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/d4VpL on line 12 PHP_EOL
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_CLASS in /in/d4VpL 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/d4VpL on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/d4VpL on line 2
Process exited with code 255.