xref: /PHP-8.2/ext/date/tests/bug-gh8471.phpt (revision 92f8f19d)
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--
47The DateTime object has not been correctly initialized by its constructor
48The DateTimeInterface object has not been correctly initialized by its constructor
49The DateTimeImmutable object has not been correctly initialized by its constructor
50The DateTimeInterface object has not been correctly initialized by its constructor
51