xref: /PHP-8.3/ext/date/tests/bug-gh8471.phpt (revision b7860cd5)
1--TEST--
2Bug GH-8471: Segmentation fault when converting immutable and mutable DateTime instances created using reflection
3--FILE--
4<?php
5$reflection = new ReflectionClass('\DateTime');
6
7$mutable = $reflection->newInstanceWithoutConstructor();
8try {
9	$immutable = \DateTimeImmutable::createFromMutable($mutable);
10} catch (Throwable $t) {
11	echo $t->getMessage(), "\n";
12}
13
14
15$reflection = new ReflectionClass('\DateTime');
16
17$mutable = $reflection->newInstanceWithoutConstructor();
18try {
19	$immutable = \DateTimeImmutable::createFromInterface($mutable);
20} catch (Throwable $t) {
21	echo $t->getMessage(), "\n";
22}
23
24
25$reflection = new ReflectionClass('\DateTimeImmutable');
26
27$immutable = $reflection->newInstanceWithoutConstructor();
28try {
29	$mutable = \DateTime::createFromImmutable($immutable);
30} catch (Throwable $t) {
31	echo $t->getMessage(), "\n";
32}
33
34
35$reflection = new ReflectionClass('\DateTimeImmutable');
36
37$immutable = $reflection->newInstanceWithoutConstructor();
38try {
39	$mutable = \DateTime::createFromInterface($immutable);
40} catch (Throwable $t) {
41	echo $t->getMessage(), "\n";
42}
43
44
45?>
46--EXPECTF--
47Object of type DateTime has not been correctly initialized by calling parent::__construct() in its constructor
48Object of type DateTime has not been correctly initialized by calling parent::__construct() in its constructor
49Object of type DateTimeImmutable has not been correctly initialized by calling parent::__construct() in its constructor
50Object of type DateTimeImmutable has not been correctly initialized by calling parent::__construct() in its constructor
51