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