3v4l.org

run code in 300+ PHP versions simultaneously
<?php class DateTimeExtended extends DateTime { public function __get($name) { switch ($name) { case 'year': return (int)$this->format('Y'); case 'month': return (int)$this->format('n'); case 'day': return (int)$this->format('j'); case 'hour': return (int)$this->format('G'); case 'minute': return (int)$this->format('i'); case 'second': return (int)$this->format('s'); case 'dayOfWeek': return (int)$this->format('w'); case 'dayOfYear': return (int)$this->format('z'); case 'weekOfYear': return (int)$this->format('W'); case 'daysInMonth': return (int)$this->format('t'); case 'timestamp': return (int)$this->format('U'); default: throw new InvalidArgumentException(sprintf('Unknown property "%s".', $name)); } } public static function createFromFormat($format, $time, $tz = null) { if ($tz) { $date = parent::createFromFormat($format, $time, $tz); } else { $date = parent::createFromFormat($format, $time); } $errors = static::getLastErrors(); if ($errors['warning_count'] !== 0 || $errors['error_count'] !== 0) { throw new InvalidArgumentException(sprintf('Unable to parse date "%s" by pattern "%s".', $time, $format)); } if (!$date instanceof self) { return new static($date->format('Y-m-d H:i:s'), $date->getTimeZone()); } return $date; } public function format($format) { $format = preg_replace_callback('/(?:f|[Мм]есяца?|[Дд]еньнед(?:ели)?)/u', array($this, 'replaceFormatCallback'), $format); return parent::format($format); } public function replaceFormatCallback(array $matches) { switch ($matches[0]) { case 'f': return mb_strtolower(en_get_month_name($this->month)); case 'Месяц': return ru_get_month_name($this->month); case 'Месяца': return ru_get_month_name($this->month, 2); case 'месяц': return mb_strtolower(ru_get_month_name($this->month)); case 'месяца': return mb_strtolower(ru_get_month_name($this->month, 2)); case 'Деньнедели': return ru_get_weekday_name($this->dayOfWeek); case 'Деньнед': return ru_get_weekday_name($this->dayOfWeek, true); case 'деньнедели': return mb_strtolower(ru_get_weekday_name($this->dayOfWeek)); case 'деньнед': return mb_strtolower(ru_get_weekday_name($this->dayOfWeek, true)); } return $matches[0]; } public static function convert($from, $to, $value) { return static::createFromFormat($from, $value)->format($to); } public static function check($format, $value) { try { static::createFromFormat($format, $value); } catch (InvalidArgumentException $e) { return false; } return true; } }
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Deprecated: Return type of DateTimeExtended::createFromFormat($format, $time, $tz = null) should either be compatible with DateTime::createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null): DateTime|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/S6XZo on line 34 Deprecated: Return type of DateTimeExtended::format($format) should either be compatible with DateTime::format(string $format): string, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/S6XZo on line 54
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 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
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_STATIC in /in/S6XZo on line 41
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STATIC in /in/S6XZo on line 41
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/S6XZo on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/S6XZo on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/S6XZo on line 5
Process exited with code 255.

preferences:
221.1 ms | 401 KiB | 344 Q