3v4l.org

run code in 300+ PHP versions simultaneously
<?php function converTo($date, $format = 'Y-m-d', $default = null, callable $funcExc = null ) { if (empty($date)) { return $default; } if (!is_string($format)) { throw new \InvalidArgumentException("Неверный формат"); } try { if (!($date instanceof \DateTime)) { if (is_numeric($date) && ( strlen($timestamp) == 13 || strlen($timestamp) == 10 )) { $date = new \DateTime("@" . $date); } elseif (strtotime($date) !== false) { $date = new \DateTime("@" . strtotime($date)); } else { $date = new \DateTime($date); } } if(!($date = $date->format($format))) { throw new \InvalidArgumentException("Произошла ошибка при приведению к заданному формату: " . $format); } } catch (\Exception $e) { if ($funcExc !== null) { call_user_func($funcExc, $date); } throw $e; } return $date; } var_dump(converTo("23/02/2013")); die; abstract class T { static public $instanses; final private function __construct(){ } public static function getInstance() { if (!(static::$instanses instanceof static)) { static::$instanses = new static; } return static::$instanses; } } class A extends T { static public $instanses; } class B extends A { static public $instanses; } $t = A::getInstance(); var_dump($t); $t1 = B::getInstance(); var_dump($t1); new B(); ?>
Output for 8.3.0 - 8.3.4, 8.3.6
Fatal error: Uncaught DateMalformedStringException: Failed to parse time string (23/02/2013) at position 0 (2): Unexpected character in /in/GNtdU:17 Stack trace: #0 /in/GNtdU(17): DateTime->__construct('23/02/2013') #1 /in/GNtdU(32): converTo('23/02/2013') #2 {main} thrown in /in/GNtdU on line 17
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Fatal error: Uncaught DateMalformedStringException: Failed to parse time string (23/02/2013) at position 0 (2): Unexpected character in /in/GNtdU:17 Stack trace: #0 /in/GNtdU(17): DateTime->__construct('23/02/2013') #1 /in/GNtdU(32): converTo('23/02/2013') #2 {main} thrown in /in/GNtdU on line 17
Process exited with code 255.
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
Fatal error: Uncaught Exception: Failed to parse time string (23/02/2013) at position 0 (2): Unexpected character in /in/GNtdU:17 Stack trace: #0 /in/GNtdU(17): DateTime->__construct('23/02/2013') #1 /in/GNtdU(32): converTo('23/02/2013') #2 {main} thrown in /in/GNtdU on line 17
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (23/02/2013) at position 0 (2): Unexpected character in /in/GNtdU:17 Stack trace: #0 /in/GNtdU(17): DateTime->__construct('23/02/2013') #1 /in/GNtdU(32): converTo('23/02/2013') #2 {main} thrown in /in/GNtdU on line 17
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (23/02/2013) at position 0 (2): Unexpected character' in /in/GNtdU:17 Stack trace: #0 /in/GNtdU(17): DateTime->__construct('23/02/2013') #1 /in/GNtdU(32): converTo('23/02/2013') #2 {main} thrown in /in/GNtdU on line 17
Process exited with code 255.

preferences:
162.93 ms | 402 KiB | 183 Q