Annotation of embedaddon/php/ext/standard/tests/serialize/serialization_objects_002.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test serialize() & unserialize() functions: objects (variations)
3: --INI--
4: serialize_precision=100
5: --FILE--
6: <?php
7: /* Prototype : proto string serialize(mixed variable)
8: * Description: Returns a string representation of variable (which can later be unserialized)
9: * Source code: ext/standard/var.c
10: * Alias to functions:
11: */
12: /* Prototype : proto mixed unserialize(string variable_representation)
13: * Description: Takes a string representation of variable and recreates it
14: * Source code: ext/standard/var.c
15: * Alias to functions:
16: */
17:
18: echo "\n--- Testing Variations in objects ---\n";
19:
20: class members
21: {
22: private $var_private = 10;
23: protected $var_protected = "string";
24: public $var_public = array(-100.123, "string", TRUE);
25: }
26:
27: class nomembers { }
28:
29: class C {
30: var $a, $b, $c, $d, $e, $f, $g, $h;
31: function __construct() {
32: $this->a = 10;
33: $this->b = "string";
34: $this->c = TRUE;
35: $this->d = -2.34444;
36: $this->e = array(1, 2.22, "string", TRUE, array(),
37: new members(), null);
38: $this->f = new nomembers();
39: $this->g = $GLOBALS['file_handle'];
40: $this->h = NULL;
41: }
42: }
43:
44: class D extends C {
45: function __construct( $w, $x, $y, $z ) {
46: $this->a = $w;
47: $this->b = $x;
48: $this->c = $y;
49: $this->d = $z;
50: }
51: }
52:
53: $variation_obj_arr = array(
54: new C(),
55: new D( 1, 2, 3333, 444444 ),
56: new D( .5, 0.005, -1.345, 10.005e5 ),
57: new D( TRUE, true, FALSE, false ),
58: new D( "a", 'a', "string", 'string' ),
59: new D( array(),
60: array(1, 2.222, TRUE, FALSE, "string"),
61: array(new nomembers(), $file_handle, NULL, ""),
62: array(array(1,2,3,array()))
63: ),
64: new D( NULL, null, "", "\0" ),
65: new D( new members, new nomembers, $file_handle, NULL),
66: );
67:
68: /* Testing serialization on all the objects through loop */
69: foreach( $variation_obj_arr as $object) {
70:
71: echo "After Serialization => ";
72: $serialize_data = serialize( $object );
73: var_dump( $serialize_data );
74:
75: echo "After Unserialization => ";
76: $unserialize_data = unserialize( $serialize_data );
77: var_dump( $unserialize_data );
78: }
79:
80: echo "\nDone";
81: ?>
82: --EXPECTF--
83: --- Testing Variations in objects ---
84:
85: Notice: Undefined index: file_handle in %s on line 34
86:
87: Notice: Undefined variable: file_handle in %s on line 56
88:
89: Notice: Undefined variable: file_handle in %s on line 60
90: After Serialization => string(493) "O:1:"C":8:{s:1:"a";i:10;s:1:"b";s:6:"string";s:1:"c";b:1;s:1:"d";d:-2.344440000000000079438677857979200780391693115234375;s:1:"e";a:7:{i:0;i:1;i:1;d:2.220000000000000195399252334027551114559173583984375;i:2;s:6:"string";i:3;b:1;i:4;a:0:{}i:5;O:7:"members":3:{s:20:"