xref: /PHP-8.2/ext/date/tests/gh10747-1.phpt (revision 5373f5dd)
1--TEST--
2Bug GH-10747 (Private fields in serialized DateTimeImmutable objects throw)
3--INI--
4date.timezone=UTC
5--FILE--
6<?php
7class I extends DateTimeImmutable
8{
9	private   int $var1 = 1;
10	private       $var2 = 0;
11	protected int $var3 = 3;
12	protected     $var4;
13
14	function __construct()
15	{
16		parent::__construct();
17		$this->var2 = 2;
18		$this->var4 = 4;
19	}
20}
21
22$i = new I;
23$s = serialize($i);
24$u = unserialize($s);
25
26var_dump($i, str_replace(chr(0), '!', $s), $u);
27?>
28--EXPECTF--
29object(I)#1 (7) {
30  ["var1":"I":private]=>
31  int(1)
32  ["var2":"I":private]=>
33  int(2)
34  ["var3":protected]=>
35  int(3)
36  ["var4":protected]=>
37  int(4)
38  ["date"]=>
39  string(%d) "%s"
40  ["timezone_type"]=>
41  int(3)
42  ["timezone"]=>
43  string(3) "UTC"
44}
45string(%d) "O:1:"I":7:{s:4:"date";s:%d:"%s";s:13:"timezone_type";i:3;s:8:"timezone";s:3:"UTC";s:7:"!I!var1";i:1;s:7:"!I!var2";i:2;s:7:"!*!var3";i:3;s:7:"!*!var4";i:4;}"
46object(I)#2 (7) {
47  ["var1":"I":private]=>
48  int(1)
49  ["var2":"I":private]=>
50  int(2)
51  ["var3":protected]=>
52  int(3)
53  ["var4":protected]=>
54  int(4)
55  ["date"]=>
56  string(%d) "%s"
57  ["timezone_type"]=>
58  int(3)
59  ["timezone"]=>
60  string(3) "UTC"
61}
62