1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
--TEST--
Bug GH-10747 (Private fields in serialized DateTimeImmutable objects throw)
--FILE--
<?php
class I extends DateTimeImmutable
{
private int $var1 = 1;
private $var2 = 0;
protected int $var3 = 3;
protected $var4;
function __construct()
{
parent::__construct();
$this->var2 = 2;
$this->var4 = 4;
}
}
$s = 'O:1:"I":7:{s:4:"date";s:26:"2023-03-09 17:03:11.123456";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;}';
$u = unserialize(str_replace('!', chr(0), $s));
var_dump($s, $u);
// this one has the class names for the private properties changed to something non-existing
$s = 'O:1:"I":7:{s:4:"date";s:26:"2023-03-09 17:03:11.123456";s:13:"timezone_type";i:3;s:8:"timezone";s:3:"UTC";s:7:"!J!var1";i:1;s:7:"!K!var2";i:2;s:7:"!*!var3";i:3;s:7:"!*!var4";i:4;}';
$u = unserialize(str_replace('!', chr(0), $s));
var_dump($s, $u);
?>
--EXPECTF--
string(179) "O:1:"I":7:{s:4:"date";s:26:"2023-03-09 17:03:11.123456";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;}"
object(I)#1 (7) {
["var1":"I":private]=>
int(1)
["var2":"I":private]=>
int(2)
["var3":protected]=>
int(3)
["var4":protected]=>
int(4)
["date"]=>
string(26) "2023-03-09 17:03:11.123456"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
string(179) "O:1:"I":7:{s:4:"date";s:26:"2023-03-09 17:03:11.123456";s:13:"timezone_type";i:3;s:8:"timezone";s:3:"UTC";s:7:"!J!var1";i:1;s:7:"!K!var2";i:2;s:7:"!*!var3";i:3;s:7:"!*!var4";i:4;}"
object(I)#2 (7) {
["var1":"I":private]=>
int(1)
["var2":"I":private]=>
int(0)
["var3":protected]=>
int(3)
["var4":protected]=>
int(4)
["date"]=>
string(26) "2023-03-09 17:03:11.123456"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
|