- var_dump: documentation ( source)
- defined: documentation ( source)
- constant: documentation ( source)
<?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());