3v4l.org

run code in 300+ PHP versions simultaneously
<?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());
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.30, 8.0.0 - 8.0.22, 8.1.0 - 8.1.9
int(61) int(60)
Output for 7.0.0 - 7.0.33
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 5.6.0 - 5.6.40
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/GvfnC on line 5
Process exited with code 255.

preferences:
51.54 ms | 411 KiB | 5 Q