xref: /php-src/ext/date/tests/bug48476.phpt (revision b7860cd5)
1--TEST--
2Bug #48476 (cloning extended DateTime class without calling parent::__constr crashed PHP)
3--FILE--
4<?php
5class MyDateTime extends DateTime {
6    public function __construct() { }
7}
8class MyDateTimeZone extends DateTimeZone {
9    public function __construct() { }
10}
11
12$o = new MyDateTime;
13try {
14    var_dump($o->format("d"));
15} catch (Error $e) {
16    echo $e::class, ': ', $e->getMessage(), "\n";
17}
18$x = clone $o;
19
20try {
21    var_dump($x->format("d"));
22} catch (Error $e) {
23    echo $e::class, ': ', $e->getMessage(), "\n";
24}
25
26clone $o;
27
28try {
29    var_dump(timezone_location_get(clone new MyDateTimezone));
30} catch (Error $e) {
31    echo $e::class, ': ', $e->getMessage(), "\n";
32}
33?>
34--EXPECT--
35DateObjectError: Object of type MyDateTime (inheriting DateTime) has not been correctly initialized by calling parent::__construct() in its constructor
36DateObjectError: Object of type MyDateTime (inheriting DateTime) has not been correctly initialized by calling parent::__construct() in its constructor
37DateObjectError: Object of type MyDateTimeZone (inheriting DateTimeZone) has not been correctly initialized by calling parent::__construct() in its constructor
38