xref: /PHP-8.0/ext/spl/tests/unserialize.phpt (revision f8d79582)
1--TEST--
2SPL: unserialize with no data (for PHPUnit)
3--FILE--
4<?php
5
6$types = array('SplDoublyLinkedList', 'SplObjectStorage', 'ArrayObject');
7
8foreach ($types as $type) {
9    // serialize an empty new object
10    $exp = serialize(new $type());
11    // hack to instantiate an object without constructor
12    $str = sprintf('C:%d:"%s":0:{}', strlen($type), $type);
13    $obj = unserialize($str);
14    var_dump($obj);
15    // serialize result
16    $out = serialize($obj);
17    // both should match
18    var_dump($exp === $out);
19}
20?>
21--EXPECTF--
22object(SplDoublyLinkedList)#%d (2) {
23  ["flags":"SplDoublyLinkedList":private]=>
24  int(0)
25  ["dllist":"SplDoublyLinkedList":private]=>
26  array(0) {
27  }
28}
29bool(true)
30object(SplObjectStorage)#%d (1) {
31  ["storage":"SplObjectStorage":private]=>
32  array(0) {
33  }
34}
35bool(true)
36object(ArrayObject)#%d (1) {
37  ["storage":"ArrayObject":private]=>
38  array(0) {
39  }
40}
41bool(true)
42