3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php interface Cachable { public function getCacheTtl(): int; } abstract class AbstractCacheItem implements Cachable { private $config = []; public function getCacheTtl(): int { return $this->config['cache_ttl'] ?? defined('static::CACHE_TTL') ? constant('static::CACHE_TTL') : 60; } } class SomeCacheItemA extends AbstractCacheItem { public const CACHE_TTL = 61; } class SomeCacheItemB extends AbstractCacheItem { } $a = new SomeCacheItemA(); $b = new SomeCacheItemB(); var_dump($a->getCacheTtl(), $b->getCacheTtl());
based on tG0j9
Output for 7.1.0 - 7.1.10
int(61) int(60)
Output for 7.0.0 - 7.0.24
Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) in /in/GvfnC on line 23
Process exited with code 255.
Output for hhvm-3.22.0
Fatal error: Uncaught Error: syntax error, unexpected T_CONST, expecting T_VARIABLE in /in/GvfnC:-1 Stack trace: #0 {main}
Process exited with code 255.
Output for hhvm-3.18.5 - 3.21.3
Fatal error: Uncaught Error: syntax error, unexpected T_CONST, expecting T_VARIABLE in /in/GvfnC:23 Stack trace: #0 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/GvfnC on line 5
Process exited with code 255.