xref: /PHP-8.1/ext/date/tests/bug67118.phpt (revision f8d79582)
1--TEST--
2Bug #67118 crashes in DateTime when this used after failed __construct
3--INI--
4date.timezone=Europe/Berlin
5--FILE--
6<?php
7class mydt extends datetime
8{
9    public function __construct($time = 'now', $tz = NULL, $format = NULL)
10    {
11        if (!empty($tz) && !is_object($tz)) {
12            $tz = new DateTimeZone($tz);
13        }
14        try {
15            @parent::__construct($time, $tz);
16        } catch (Exception $e) {
17            echo "Bad date" . $this->format("Y") . "\n";
18        }
19    }
20
21};
22
23new mydt("Funktionsansvarig rådgivning och juridik", "UTC");
24?>
25--EXPECTF--
26Fatal error: Uncaught Error: The DateTime object has not been correctly initialized by its constructor in %s:%d
27Stack trace:
28#0 %s(%d): DateTime->format('Y')
29#1 %s(%d): mydt->__construct(%s)
30#2 {main}
31  thrown in %s on line %d
32