3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class TimeCurrency { public static function createFromString(string $formatted): self { if (!preg_match('/^(\d{4}):(\d{2}):(\d{1}):(\d{2}):(\d{2})$/', $formatted, $matches)) { throw new \InvalidArgumentException('Invalid currency format.'); } return new self(...array_slice($matches, 1)); } /** @var int */ private $year; /** @var int */ private $weekNumber; /** @var int */ private $day; /** @var int */ private $hour; /** @var int */ private $minute; public function __construct(int $year, int $weekNumber, int $day, int $hour, int $minute) { $this->year = $year; $this->weekNumber = $weekNumber; $this->day = $day; $this->hour = $hour; $this->minute = $minute; } public function addYears(int $addedYears): void { $this->year += $addedYears; } public function __toString(): string { return sprintf('%04d:%02d:%d:%02d:%02d', $this->year, $this->weekNumber, $this->day, $this->hour, $this->minute); } } // Example usage $currency = TimeCurrency::createFromString('2010:21:1:23:21'); $currency->addYears(4); echo $currency;
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
2014:21:1:23:21

preferences:
113.31 ms | 1474 KiB | 4 Q