Skip to content

Commit 1be0975

Browse files
author
Thies C. Arntzen
committed
added test for serialize
changed var.c to use Z_* macros
1 parent 6708768 commit 1be0975

File tree

3 files changed

+168
-61
lines changed

3 files changed

+168
-61
lines changed

ext/standard/php_var.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ PHP_FUNCTION(var_dump);
2525
PHP_FUNCTION(serialize);
2626
PHP_FUNCTION(unserialize);
2727

28-
void php_var_dump(pval **struc, int level);
28+
void php_var_dump(zval **struc, int level);
2929

3030
/* typdef HashTable php_serialize_data_t; */
3131
#define php_serialize_data_t HashTable
3232

33-
PHPAPI void php_var_serialize(pval *buf, pval **struc, php_serialize_data_t *var_hash);
34-
PHPAPI int php_var_unserialize(pval **rval, const char **p, const char *max, php_serialize_data_t *var_hash);
33+
PHPAPI void php_var_serialize(zval *buf, zval **struc, php_serialize_data_t *var_hash);
34+
PHPAPI int php_var_unserialize(zval **rval, const char **p, const char *max, php_serialize_data_t *var_hash);
3535

3636
#define PHP_VAR_SERIALIZE_INIT(var_hash) \
3737
zend_hash_init(&(var_hash),10,NULL,NULL,0)

ext/standard/tests/serialize/001.phpt

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
--TEST--
2+
serialize()/unserialize()/var_dump()
3+
--POST--
4+
--GET--
5+
--FILE--
6+
<?php
7+
class t
8+
{
9+
function t()
10+
{
11+
$this->a = "hallo";
12+
}
13+
}
14+
15+
class s
16+
{
17+
function s()
18+
{
19+
$this->a = "hallo";
20+
$this->b = "php";
21+
$this->c = "world";
22+
}
23+
24+
function __sleep()
25+
{
26+
echo "__sleep called\n";
27+
return array("a","c");
28+
}
29+
30+
function __wakeup()
31+
{
32+
echo "__wakeup called\n";
33+
}
34+
}
35+
36+
37+
echo serialize(NULL)."\n";
38+
echo serialize((bool) true)."\n";
39+
echo serialize((bool) false)."\n";
40+
echo serialize(1)."\n";
41+
echo serialize(0)."\n";
42+
echo serialize(-1)."\n";
43+
echo serialize(1.123456789)."\n";
44+
echo serialize(1.0)."\n";
45+
echo serialize(0.0)."\n";
46+
echo serialize(-1.0)."\n";
47+
echo serialize(-1.123456789)."\n";
48+
echo serialize("hallo")."\n";
49+
echo serialize(array(1,1.1,"hallo",NULL,true,array()))."\n";
50+
51+
$t = new t();
52+
$data = serialize($t);
53+
echo "$data\n";
54+
$t = unserialize($data);
55+
var_dump($t);
56+
57+
$t = new s();
58+
$data = serialize($t);
59+
echo "$data\n";
60+
$t = unserialize($data);
61+
var_dump($t);
62+
63+
$a = array("a" => "test");
64+
$a[ "b" ] = &$a[ "a" ];
65+
var_dump($a);
66+
$data = serialize($a);
67+
echo "$data\n";
68+
$a = unserialize($data);
69+
var_dump($a);
70+
?>
71+
--EXPECT--
72+
N;
73+
b:1;
74+
b:0;
75+
i:1;
76+
i:0;
77+
i:-1;
78+
d:1.123456789;
79+
d:1;
80+
d:0;
81+
d:-1;
82+
d:-1.123456789;
83+
s:5:"hallo";
84+
a:6:{i:0;i:1;i:1;d:1.1;i:2;s:5:"hallo";i:3;N;i:4;b:1;i:5;a:0:{}}
85+
O:1:"t":1:{s:1:"a";s:5:"hallo";}
86+
object(t)(1) {
87+
["a"]=>
88+
string(5) "hallo"
89+
}
90+
__sleep called
91+
O:1:"s":2:{s:1:"a";s:5:"hallo";s:1:"c";s:5:"world";}
92+
__wakeup called
93+
object(s)(2) {
94+
["a"]=>
95+
string(5) "hallo"
96+
["c"]=>
97+
string(5) "world"
98+
}
99+
array(2) {
100+
["a"]=>
101+
&string(4) "test"
102+
["b"]=>
103+
&string(4) "test"
104+
}
105+
a:2:{s:1:"a";s:4:"test";s:1:"b";R:2;}
106+
array(2) {
107+
["a"]=>
108+
&string(4) "test"
109+
["b"]=>
110+
&string(4) "test"
111+
}

0 commit comments

Comments
 (0)