summaryrefslogtreecommitdiff
path: root/ext/standard/tests/serialize/serialization_objects_012.phpt
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2013-03-14 05:42:27 +0000
committer <>2013-04-03 16:25:08 +0000
commitc4dd7a1a684490673e25aaf4fabec5df138854c4 (patch)
tree4d57c44caae4480efff02b90b9be86f44bf25409 /ext/standard/tests/serialize/serialization_objects_012.phpt
downloadphp2-master.tar.gz
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'ext/standard/tests/serialize/serialization_objects_012.phpt')
-rw-r--r--ext/standard/tests/serialize/serialization_objects_012.phpt244
1 files changed, 244 insertions, 0 deletions
diff --git a/ext/standard/tests/serialize/serialization_objects_012.phpt b/ext/standard/tests/serialize/serialization_objects_012.phpt
new file mode 100644
index 0000000..f994d8e
--- /dev/null
+++ b/ext/standard/tests/serialize/serialization_objects_012.phpt
@@ -0,0 +1,244 @@
+--TEST--
+Object serialization / unserialization: real references and COW references
+--FILE--
+<?php
+/* Prototype : proto string serialize(mixed variable)
+ * Description: Returns a string representation of variable (which can later be unserialized)
+ * Source code: ext/standard/var.c
+ * Alias to functions:
+ */
+/* Prototype : proto mixed unserialize(string variable_representation)
+ * Description: Takes a string representation of variable and recreates it
+ * Source code: ext/standard/var.c
+ * Alias to functions:
+ */
+
+echo "\n\nArray containing same object twice:\n";
+$obj = new stdclass;
+$a[0] = $obj;
+$a[1] = $a[0];
+var_dump($a);
+
+$ser = serialize($a);
+var_dump($ser);
+
+$ua = unserialize($ser);
+var_dump($ua);
+$ua[0]->a = "newProp";
+var_dump($ua);
+$ua[0] = "a0.changed";
+var_dump($ua);
+
+
+echo "\n\nArray containing object and reference to that object:\n";
+$obj = new stdclass;
+$a[0] = $obj;
+$a[1] = &$a[0];
+var_dump($a);
+
+$ser = serialize($a);
+var_dump($ser);
+
+$ua = unserialize($ser);
+var_dump($ua);
+$ua[0]->a = "newProp";
+var_dump($ua);
+$ua[0] = "a0.changed";
+var_dump($ua);
+
+echo "\n\nObject containing same object twice:";
+$obj = new stdclass;
+$contaner = new stdclass;
+$contaner->a = $obj;
+$contaner->b = $contaner->a;
+var_dump($contaner);
+
+$ser = serialize($contaner);
+var_dump($ser);
+
+$ucontainer = unserialize($ser);
+var_dump($ucontainer);
+$ucontainer->a->a = "newProp";
+var_dump($ucontainer);
+$ucontainer->a = "container->a.changed";
+var_dump($ucontainer);
+
+
+echo "\n\nObject containing object and reference to that object:\n";
+$obj = new stdclass;
+$contaner = new stdclass;
+$contaner->a = $obj;
+$contaner->b = &$contaner->a;
+var_dump($contaner);
+
+$ser = serialize($contaner);
+var_dump($ser);
+
+$ucontainer = unserialize($ser);
+var_dump($ucontainer);
+$ucontainer->a->a = "newProp";
+var_dump($ucontainer);
+$ucontainer->b = "container->a.changed";
+var_dump($ucontainer);
+
+echo "Done";
+?>
+--EXPECTF--
+
+
+Array containing same object twice:
+array(2) {
+ [0]=>
+ object(stdClass)#%d (0) {
+ }
+ [1]=>
+ object(stdClass)#%d (0) {
+ }
+}
+string(37) "a:2:{i:0;O:8:"stdClass":0:{}i:1;r:2;}"
+array(2) {
+ [0]=>
+ object(stdClass)#%d (0) {
+ }
+ [1]=>
+ object(stdClass)#%d (0) {
+ }
+}
+array(2) {
+ [0]=>
+ object(stdClass)#%d (1) {
+ ["a"]=>
+ string(7) "newProp"
+ }
+ [1]=>
+ object(stdClass)#%d (1) {
+ ["a"]=>
+ string(7) "newProp"
+ }
+}
+array(2) {
+ [0]=>
+ string(10) "a0.changed"
+ [1]=>
+ object(stdClass)#%d (1) {
+ ["a"]=>
+ string(7) "newProp"
+ }
+}
+
+
+Array containing object and reference to that object:
+array(2) {
+ [0]=>
+ &object(stdClass)#%d (0) {
+ }
+ [1]=>
+ &object(stdClass)#%d (0) {
+ }
+}
+string(37) "a:2:{i:0;O:8:"stdClass":0:{}i:1;R:2;}"
+array(2) {
+ [0]=>
+ &object(stdClass)#%d (0) {
+ }
+ [1]=>
+ &object(stdClass)#%d (0) {
+ }
+}
+array(2) {
+ [0]=>
+ &object(stdClass)#%d (1) {
+ ["a"]=>
+ string(7) "newProp"
+ }
+ [1]=>
+ &object(stdClass)#%d (1) {
+ ["a"]=>
+ string(7) "newProp"
+ }
+}
+array(2) {
+ [0]=>
+ &string(10) "a0.changed"
+ [1]=>
+ &string(10) "a0.changed"
+}
+
+
+Object containing same object twice:object(stdClass)#%d (2) {
+ ["a"]=>
+ object(stdClass)#%d (0) {
+ }
+ ["b"]=>
+ object(stdClass)#%d (0) {
+ }
+}
+string(58) "O:8:"stdClass":2:{s:1:"a";O:8:"stdClass":0:{}s:1:"b";r:2;}"
+object(stdClass)#%d (2) {
+ ["a"]=>
+ object(stdClass)#%d (0) {
+ }
+ ["b"]=>
+ object(stdClass)#%d (0) {
+ }
+}
+object(stdClass)#%d (2) {
+ ["a"]=>
+ object(stdClass)#%d (1) {
+ ["a"]=>
+ string(7) "newProp"
+ }
+ ["b"]=>
+ object(stdClass)#%d (1) {
+ ["a"]=>
+ string(7) "newProp"
+ }
+}
+object(stdClass)#%d (2) {
+ ["a"]=>
+ string(20) "container->a.changed"
+ ["b"]=>
+ object(stdClass)#%d (1) {
+ ["a"]=>
+ string(7) "newProp"
+ }
+}
+
+
+Object containing object and reference to that object:
+object(stdClass)#%d (2) {
+ ["a"]=>
+ &object(stdClass)#%d (0) {
+ }
+ ["b"]=>
+ &object(stdClass)#%d (0) {
+ }
+}
+string(58) "O:8:"stdClass":2:{s:1:"a";O:8:"stdClass":0:{}s:1:"b";R:2;}"
+object(stdClass)#%d (2) {
+ ["a"]=>
+ &object(stdClass)#%d (0) {
+ }
+ ["b"]=>
+ &object(stdClass)#%d (0) {
+ }
+}
+object(stdClass)#%d (2) {
+ ["a"]=>
+ &object(stdClass)#%d (1) {
+ ["a"]=>
+ string(7) "newProp"
+ }
+ ["b"]=>
+ &object(stdClass)#%d (1) {
+ ["a"]=>
+ string(7) "newProp"
+ }
+}
+object(stdClass)#%d (2) {
+ ["a"]=>
+ &string(20) "container->a.changed"
+ ["b"]=>
+ &string(20) "container->a.changed"
+}
+Done \ No newline at end of file