Annotation of embedaddon/php/ext/standard/tests/serialize/serialization_objects_012.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Object serialization / unserialization: real references and COW references
! 3: --FILE--
! 4: <?php
! 5: /* Prototype : proto string serialize(mixed variable)
! 6: * Description: Returns a string representation of variable (which can later be unserialized)
! 7: * Source code: ext/standard/var.c
! 8: * Alias to functions:
! 9: */
! 10: /* Prototype : proto mixed unserialize(string variable_representation)
! 11: * Description: Takes a string representation of variable and recreates it
! 12: * Source code: ext/standard/var.c
! 13: * Alias to functions:
! 14: */
! 15:
! 16: echo "\n\nArray containing same object twice:\n";
! 17: $obj = new stdclass;
! 18: $a[0] = $obj;
! 19: $a[1] = $a[0];
! 20: var_dump($a);
! 21:
! 22: $ser = serialize($a);
! 23: var_dump($ser);
! 24:
! 25: $ua = unserialize($ser);
! 26: var_dump($ua);
! 27: $ua[0]->a = "newProp";
! 28: var_dump($ua);
! 29: $ua[0] = "a0.changed";
! 30: var_dump($ua);
! 31:
! 32:
! 33: echo "\n\nArray containing object and reference to that object:\n";
! 34: $obj = new stdclass;
! 35: $a[0] = $obj;
! 36: $a[1] = &$a[0];
! 37: var_dump($a);
! 38:
! 39: $ser = serialize($a);
! 40: var_dump($ser);
! 41:
! 42: $ua = unserialize($ser);
! 43: var_dump($ua);
! 44: $ua[0]->a = "newProp";
! 45: var_dump($ua);
! 46: $ua[0] = "a0.changed";
! 47: var_dump($ua);
! 48:
! 49: echo "\n\nObject containing same object twice:";
! 50: $obj = new stdclass;
! 51: $contaner = new stdclass;
! 52: $contaner->a = $obj;
! 53: $contaner->b = $contaner->a;
! 54: var_dump($contaner);
! 55:
! 56: $ser = serialize($contaner);
! 57: var_dump($ser);
! 58:
! 59: $ucontainer = unserialize($ser);
! 60: var_dump($ucontainer);
! 61: $ucontainer->a->a = "newProp";
! 62: var_dump($ucontainer);
! 63: $ucontainer->a = "container->a.changed";
! 64: var_dump($ucontainer);
! 65:
! 66:
! 67: echo "\n\nObject containing object and reference to that object:\n";
! 68: $obj = new stdclass;
! 69: $contaner = new stdclass;
! 70: $contaner->a = $obj;
! 71: $contaner->b = &$contaner->a;
! 72: var_dump($contaner);
! 73:
! 74: $ser = serialize($contaner);
! 75: var_dump($ser);
! 76:
! 77: $ucontainer = unserialize($ser);
! 78: var_dump($ucontainer);
! 79: $ucontainer->a->a = "newProp";
! 80: var_dump($ucontainer);
! 81: $ucontainer->b = "container->a.changed";
! 82: var_dump($ucontainer);
! 83:
! 84: echo "Done";
! 85: ?>
! 86: --EXPECTF--
! 87:
! 88:
! 89: Array containing same object twice:
! 90: array(2) {
! 91: [0]=>
! 92: object(stdClass)#%d (0) {
! 93: }
! 94: [1]=>
! 95: object(stdClass)#%d (0) {
! 96: }
! 97: }
! 98: string(37) "a:2:{i:0;O:8:"stdClass":0:{}i:1;r:2;}"
! 99: array(2) {
! 100: [0]=>
! 101: object(stdClass)#%d (0) {
! 102: }
! 103: [1]=>
! 104: object(stdClass)#%d (0) {
! 105: }
! 106: }
! 107: array(2) {
! 108: [0]=>
! 109: object(stdClass)#%d (1) {
! 110: ["a"]=>
! 111: string(7) "newProp"
! 112: }
! 113: [1]=>
! 114: object(stdClass)#%d (1) {
! 115: ["a"]=>
! 116: string(7) "newProp"
! 117: }
! 118: }
! 119: array(2) {
! 120: [0]=>
! 121: string(10) "a0.changed"
! 122: [1]=>
! 123: object(stdClass)#%d (1) {
! 124: ["a"]=>
! 125: string(7) "newProp"
! 126: }
! 127: }
! 128:
! 129:
! 130: Array containing object and reference to that object:
! 131: array(2) {
! 132: [0]=>
! 133: &object(stdClass)#%d (0) {
! 134: }
! 135: [1]=>
! 136: &object(stdClass)#%d (0) {
! 137: }
! 138: }
! 139: string(37) "a:2:{i:0;O:8:"stdClass":0:{}i:1;R:2;}"
! 140: array(2) {
! 141: [0]=>
! 142: &object(stdClass)#%d (0) {
! 143: }
! 144: [1]=>
! 145: &object(stdClass)#%d (0) {
! 146: }
! 147: }
! 148: array(2) {
! 149: [0]=>
! 150: &object(stdClass)#%d (1) {
! 151: ["a"]=>
! 152: string(7) "newProp"
! 153: }
! 154: [1]=>
! 155: &object(stdClass)#%d (1) {
! 156: ["a"]=>
! 157: string(7) "newProp"
! 158: }
! 159: }
! 160: array(2) {
! 161: [0]=>
! 162: &string(10) "a0.changed"
! 163: [1]=>
! 164: &string(10) "a0.changed"
! 165: }
! 166:
! 167:
! 168: Object containing same object twice:object(stdClass)#%d (2) {
! 169: ["a"]=>
! 170: object(stdClass)#%d (0) {
! 171: }
! 172: ["b"]=>
! 173: object(stdClass)#%d (0) {
! 174: }
! 175: }
! 176: string(58) "O:8:"stdClass":2:{s:1:"a";O:8:"stdClass":0:{}s:1:"b";r:2;}"
! 177: object(stdClass)#%d (2) {
! 178: ["a"]=>
! 179: object(stdClass)#%d (0) {
! 180: }
! 181: ["b"]=>
! 182: object(stdClass)#%d (0) {
! 183: }
! 184: }
! 185: object(stdClass)#%d (2) {
! 186: ["a"]=>
! 187: object(stdClass)#%d (1) {
! 188: ["a"]=>
! 189: string(7) "newProp"
! 190: }
! 191: ["b"]=>
! 192: object(stdClass)#%d (1) {
! 193: ["a"]=>
! 194: string(7) "newProp"
! 195: }
! 196: }
! 197: object(stdClass)#%d (2) {
! 198: ["a"]=>
! 199: string(20) "container->a.changed"
! 200: ["b"]=>
! 201: object(stdClass)#%d (1) {
! 202: ["a"]=>
! 203: string(7) "newProp"
! 204: }
! 205: }
! 206:
! 207:
! 208: Object containing object and reference to that object:
! 209: object(stdClass)#%d (2) {
! 210: ["a"]=>
! 211: &object(stdClass)#%d (0) {
! 212: }
! 213: ["b"]=>
! 214: &object(stdClass)#%d (0) {
! 215: }
! 216: }
! 217: string(58) "O:8:"stdClass":2:{s:1:"a";O:8:"stdClass":0:{}s:1:"b";R:2;}"
! 218: object(stdClass)#%d (2) {
! 219: ["a"]=>
! 220: &object(stdClass)#%d (0) {
! 221: }
! 222: ["b"]=>
! 223: &object(stdClass)#%d (0) {
! 224: }
! 225: }
! 226: object(stdClass)#%d (2) {
! 227: ["a"]=>
! 228: &object(stdClass)#%d (1) {
! 229: ["a"]=>
! 230: string(7) "newProp"
! 231: }
! 232: ["b"]=>
! 233: &object(stdClass)#%d (1) {
! 234: ["a"]=>
! 235: string(7) "newProp"
! 236: }
! 237: }
! 238: object(stdClass)#%d (2) {
! 239: ["a"]=>
! 240: &string(20) "container->a.changed"
! 241: ["b"]=>
! 242: &string(20) "container->a.changed"
! 243: }
! 244: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>