xref: /php-src/ext/gmp/tests/serialize.phpt (revision adb45a63)
1--TEST--
2GMP serialization and unserialization
3--EXTENSIONS--
4gmp
5--FILE--
6<?php
7
8var_dump($n = gmp_init(42));
9var_dump($s = serialize($n));
10var_dump(unserialize($s));
11
12$n = gmp_init(13);
13$n->foo = "bar";
14var_dump($s = serialize($n));
15var_dump(unserialize($s));
16
17var_dump(unserialize('C:3:"GMP":15:{s:2:"42";a:0:{}}'));
18
19try {
20    unserialize('C:3:"GMP":0:{}');
21} catch (Exception $e) { var_dump($e->getMessage()); }
22
23try {
24    unserialize('C:3:"GMP":9:{s:2:"42";}');
25} catch (Exception $e) { var_dump($e->getMessage()); }
26
27try {
28    unserialize('O:3:"GMP":0:{}');
29} catch (Exception $e) { var_dump($e->getMessage()); }
30
31try {
32    unserialize('O:3:"GMP":1:{i:0;i:0;}');
33} catch (Exception $e) { var_dump($e->getMessage()); }
34
35try {
36    unserialize('O:3:"GMP":1:{i:0;s:0:"";}');
37} catch (Exception $e) { var_dump($e->getMessage()); }
38
39try {
40    unserialize('O:3:"GMP":2:{i:0;s:1:"0";i:1;i:0;}');
41} catch (Exception $e) { var_dump($e->getMessage()); }
42
43?>
44--EXPECTF--
45object(GMP)#%d (1) {
46  ["num"]=>
47  string(2) "42"
48}
49string(27) "O:3:"GMP":1:{i:0;s:2:"2a";}"
50object(GMP)#%d (1) {
51  ["num"]=>
52  string(2) "42"
53}
54
55Deprecated: Creation of dynamic property GMP::$foo is deprecated in %s on line %d
56string(56) "O:3:"GMP":2:{i:0;s:1:"d";i:1;a:1:{s:3:"foo";s:3:"bar";}}"
57
58Deprecated: Creation of dynamic property GMP::$foo is deprecated in %s on line %d
59object(GMP)#%d (2) {
60  ["foo"]=>
61  string(3) "bar"
62  ["num"]=>
63  string(2) "13"
64}
65object(GMP)#1 (1) {
66  ["num"]=>
67  string(2) "42"
68}
69string(28) "Could not unserialize number"
70string(32) "Could not unserialize properties"
71string(28) "Could not unserialize number"
72string(28) "Could not unserialize number"
73string(28) "Could not unserialize number"
74string(32) "Could not unserialize properties"
75