diff options
Diffstat (limited to 'ext/standard/tests/serialize')
58 files changed, 5055 insertions, 0 deletions
diff --git a/ext/standard/tests/serialize/001.phpt b/ext/standard/tests/serialize/001.phpt new file mode 100644 index 0000000..600c9b7 --- /dev/null +++ b/ext/standard/tests/serialize/001.phpt @@ -0,0 +1,122 @@ +--TEST-- +serialize()/unserialize()/var_dump() +--INI-- +serialize_precision=100 +--FILE-- +<?php +class t +{ + function t() + { + $this->a = "hallo"; + } +} + +class s +{ + public $a; + public $b; + public $c; + + function s() + { + $this->a = "hallo"; + $this->b = "php"; + $this->c = "world"; + $this->d = "!"; + } + + function __sleep() + { + echo "__sleep called\n"; + return array("a","c"); + } + + function __wakeup() + { + echo "__wakeup called\n"; + } +} + + +echo serialize(NULL)."\n"; +echo serialize((bool) true)."\n"; +echo serialize((bool) false)."\n"; +echo serialize(1)."\n"; +echo serialize(0)."\n"; +echo serialize(-1)."\n"; +echo serialize(2147483647)."\n"; +echo serialize(-2147483647)."\n"; +echo serialize(1.123456789)."\n"; +echo serialize(1.0)."\n"; +echo serialize(0.0)."\n"; +echo serialize(-1.0)."\n"; +echo serialize(-1.123456789)."\n"; +echo serialize("hallo")."\n"; +echo serialize(array(1,1.1,"hallo",NULL,true,array()))."\n"; + +$t = new t(); +$data = serialize($t); +echo "$data\n"; +$t = unserialize($data); +var_dump($t); + +$t = new s(); +$data = serialize($t); +echo "$data\n"; +$t = unserialize($data); +var_dump($t); + +$a = array("a" => "test"); +$a[ "b" ] = &$a[ "a" ]; +var_dump($a); +$data = serialize($a); +echo "$data\n"; +$a = unserialize($data); +var_dump($a); +?> +--EXPECTF-- +N; +b:1; +b:0; +i:1; +i:0; +i:-1; +i:2147483647; +i:-2147483647; +d:1.123456789000000011213842299184761941432952880859375; +d:1; +d:0; +d:-1; +d:-1.123456789000000011213842299184761941432952880859375; +s:5:"hallo"; +a:6:{i:0;i:1;i:1;d:1.100000000000000088817841970012523233890533447265625;i:2;s:5:"hallo";i:3;N;i:4;b:1;i:5;a:0:{}} +O:1:"t":1:{s:1:"a";s:5:"hallo";} +object(t)#%d (1) { + ["a"]=> + string(5) "hallo" +} +__sleep called +O:1:"s":2:{s:1:"a";s:5:"hallo";s:1:"c";s:5:"world";} +__wakeup called +object(s)#%d (3) { + ["a"]=> + string(5) "hallo" + ["b"]=> + NULL + ["c"]=> + string(5) "world" +} +array(2) { + ["a"]=> + &string(4) "test" + ["b"]=> + &string(4) "test" +} +a:2:{s:1:"a";s:4:"test";s:1:"b";R:2;} +array(2) { + ["a"]=> + &string(4) "test" + ["b"]=> + &string(4) "test" +} diff --git a/ext/standard/tests/serialize/002.phpt b/ext/standard/tests/serialize/002.phpt new file mode 100644 index 0000000..3085d1c --- /dev/null +++ b/ext/standard/tests/serialize/002.phpt @@ -0,0 +1,44 @@ +--TEST-- +Bug #25378 (unserialize() crashes with invalid data) +--FILE-- +<?php +var_dump(unserialize('b:0;')); +var_dump(unserialize('b:1;')); +var_dump(unserialize('i:823;')); +var_dump(unserialize('s:0:"";')); +var_dump(unserialize('s:3:"foo";')); +var_dump(unserialize('a:1:{i:0;s:2:"12";}')); +var_dump(unserialize('a:2:{i:0;a:0:{}i:1;a:0:{}}')); +var_dump(unserialize('a:3:{i:0;s:3:"foo";i:1;s:3:"bar";i:2;s:3:"baz";}')); +var_dump(unserialize('O:8:"stdClass":0:{}')); +?> +===DONE=== +--EXPECTF-- +bool(false) +bool(true) +int(823) +string(0) "" +string(3) "foo" +array(1) { + [0]=> + string(2) "12" +} +array(2) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } +} +array(3) { + [0]=> + string(3) "foo" + [1]=> + string(3) "bar" + [2]=> + string(3) "baz" +} +object(stdClass)#%d (0) { +} +===DONE=== diff --git a/ext/standard/tests/serialize/003.phpt b/ext/standard/tests/serialize/003.phpt new file mode 100644 index 0000000..edbcb1f --- /dev/null +++ b/ext/standard/tests/serialize/003.phpt @@ -0,0 +1,25 @@ +--TEST-- +unserialize() floats with E notation (#18654) +--INI-- +precision=12 +serialize_precision=100 +--FILE-- +<?php +foreach(array(1e2, 5.2e25, 85.29e-23, 9e-9) AS $value) { + echo ($ser = serialize($value))."\n"; + var_dump(unserialize($ser)); + echo "\n"; +} +?> +--EXPECTREGEX-- +d:100; +float\(100\) + +d:5[0-9]*; +float\(5\.2E\+25\) + +d:8\.52[89][0-9]+E-22; +float\(8\.529E-22\) + +d:8\.[9]*[0-9]*E-9; +float\(9\.0E-9\) diff --git a/ext/standard/tests/serialize/004.phpt b/ext/standard/tests/serialize/004.phpt new file mode 100644 index 0000000..a4a7c68 --- /dev/null +++ b/ext/standard/tests/serialize/004.phpt @@ -0,0 +1,33 @@ +--TEST-- +serialize()/unserialize() floats in array. +--INI-- +precision=12 +serialize_precision=100 +--FILE-- +<?php +error_reporting (E_ALL); +$a = array(4); +$str = serialize($a); +print('Serialized array: '.$str."\n"); +$b = unserialize($str); +print('Unserialized array: '); +var_dump($b); +print("\n"); +$str = serialize(array(4.5)); +print('Serialized array: '.$str."\n"); +$b = unserialize($str); +print('Unserialized array: ') ; +var_dump($b); +?> +--EXPECT-- +Serialized array: a:1:{i:0;i:4;} +Unserialized array: array(1) { + [0]=> + int(4) +} + +Serialized array: a:1:{i:0;d:4.5;} +Unserialized array: array(1) { + [0]=> + float(4.5) +} diff --git a/ext/standard/tests/serialize/005.phpt b/ext/standard/tests/serialize/005.phpt new file mode 100644 index 0000000..e7b23db --- /dev/null +++ b/ext/standard/tests/serialize/005.phpt @@ -0,0 +1,186 @@ +--TEST-- +serialize()/unserialize() objects +--SKIPIF-- +<?php if (!interface_exists('Serializable')) die('skip Interface Serialzable not defined'); ?> +--FILE-- +<?php + +// This test verifies that old and new style (un)serializing do not interfere. + +function do_autoload($class_name) +{ + if ($class_name != 'autoload_not_available') + { + require_once(dirname(__FILE__) . '/' . strtolower($class_name) . '.p5c'); + } + echo __FUNCTION__ . "($class_name)\n"; +} + +function unserializer($class_name) +{ + echo __METHOD__ . "($class_name)\n"; + switch($class_name) + { + case 'TestNAOld': + eval("class TestNAOld extends TestOld {}"); + break; + case 'TestNANew': + eval("class TestNANew extends TestNew {}"); + break; + case 'TestNANew2': + eval("class TestNANew2 extends TestNew {}"); + break; + default: + echo "Try __autoload()\n"; + if (!function_exists('__autoload')) + { + eval('function __autoload($class_name) { do_autoload($class_name); }'); + } + __autoload($class_name); + break; + } +} + +ini_set('unserialize_callback_func', 'unserializer'); + +class TestOld +{ + function serialize() + { + echo __METHOD__ . "()\n"; + } + + function unserialize($serialized) + { + echo __METHOD__ . "()\n"; + } + + function __wakeup() + { + echo __METHOD__ . "()\n"; + } + + function __sleep() + { + echo __METHOD__ . "()\n"; + return array(); + } +} + +class TestNew implements Serializable +{ + protected static $check = 0; + + function serialize() + { + echo __METHOD__ . "()\n"; + switch(++self::$check) + { + case 1: + return NULL; + case 2: + return "2"; + } + } + + function unserialize($serialized) + { + echo __METHOD__ . "()\n"; + } + + function __wakeup() + { + echo __METHOD__ . "()\n"; + } + + function __sleep() + { + echo __METHOD__ . "()\n"; + } +} + +echo "===O1===\n"; +var_dump($ser = serialize(new TestOld)); +var_dump(unserialize($ser)); + +echo "===N1===\n"; +var_dump($ser = serialize(new TestNew)); +var_dump(unserialize($ser)); + +echo "===N2===\n"; +var_dump($ser = serialize(new TestNew)); +var_dump(unserialize($ser)); + +echo "===NAOld===\n"; +var_dump(unserialize('O:9:"TestNAOld":0:{}')); + +echo "===NANew===\n"; +var_dump(unserialize('O:9:"TestNANew":0:{}')); + +echo "===NANew2===\n"; +var_dump(unserialize('C:10:"TestNANew2":0:{}')); + +echo "===AutoOld===\n"; +var_dump(unserialize('O:19:"autoload_implements":0:{}')); + +// Now we have __autoload(), that will be called before the old style header. +// If the old style handler also fails to register the class then the object +// becomes an incomplete class instance. + +echo "===AutoNA===\n"; +var_dump(unserialize('O:22:"autoload_not_available":0:{}')); +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +===O1=== +TestOld::__sleep() +string(18) "O:7:"TestOld":0:{}" +TestOld::__wakeup() +object(TestOld)#%d (0) { +} +===N1=== +TestNew::serialize() +string(2) "N;" +NULL +===N2=== +TestNew::serialize() +string(19) "C:7:"TestNew":1:{2}" +TestNew::unserialize() +object(TestNew)#%d (0) { +} +===NAOld=== +unserializer(TestNAOld) +TestOld::__wakeup() +object(TestNAOld)#%d (0) { +} +===NANew=== +unserializer(TestNANew) +TestNew::__wakeup() +object(TestNANew)#%d (0) { +} +===NANew2=== +unserializer(TestNANew2) +TestNew::unserialize() +object(TestNANew2)#%d (0) { +} +===AutoOld=== +unserializer(autoload_implements) +Try __autoload() +do_autoload(autoload_interface) +do_autoload(autoload_implements) +object(autoload_implements)#%d (0) { +} +===AutoNA=== +do_autoload(autoload_not_available) +unserializer(autoload_not_available) +Try __autoload() +do_autoload(autoload_not_available) +do_autoload(autoload_not_available) + +Warning: unserialize(): Function unserializer() hasn't defined the class it was called for in %s005.php on line %d +object(__PHP_Incomplete_Class)#%d (1) { + ["__PHP_Incomplete_Class_Name"]=> + string(22) "autoload_not_available" +} +===DONE=== diff --git a/ext/standard/tests/serialize/006.phpt b/ext/standard/tests/serialize/006.phpt new file mode 100644 index 0000000..fb813bc --- /dev/null +++ b/ext/standard/tests/serialize/006.phpt @@ -0,0 +1,29 @@ +--TEST-- +serialize()/unserialize() with exotic letters +--FILE-- +<?php + $åäöÅÄÖ = array('åäöÅÄÖ' => 'åäöÅÄÖ'); + + class ÜberKööliäå + { + public $åäöÅÄÖüÜber = 'åäöÅÄÖ'; + } + + $foo = new Überkööliäå(); + + var_dump(serialize($foo)); + var_dump(unserialize(serialize($foo))); + var_dump(serialize($åäöÅÄÖ)); + var_dump(unserialize(serialize($åäöÅÄÖ))); +?> +--EXPECT-- +string(55) "O:11:"ÜberKööliäå":1:{s:11:"åäöÅÄÖüÜber";s:6:"åäöÅÄÖ";}" +object(ÜberKööliäå)#2 (1) { + ["åäöÅÄÖüÜber"]=> + string(6) "åäöÅÄÖ" +} +string(32) "a:1:{s:6:"åäöÅÄÖ";s:6:"åäöÅÄÖ";}" +array(1) { + ["åäöÅÄÖ"]=> + string(6) "åäöÅÄÖ" +} diff --git a/ext/standard/tests/serialize/autoload_implements.p5c b/ext/standard/tests/serialize/autoload_implements.p5c new file mode 100755 index 0000000..2c3479c --- /dev/null +++ b/ext/standard/tests/serialize/autoload_implements.p5c @@ -0,0 +1,10 @@ +<?php + +class autoload_implements implements autoload_interface { + function testFunction() + { + return true; + } +} + +?>
\ No newline at end of file diff --git a/ext/standard/tests/serialize/autoload_interface.p5c b/ext/standard/tests/serialize/autoload_interface.p5c new file mode 100755 index 0000000..6908155 --- /dev/null +++ b/ext/standard/tests/serialize/autoload_interface.p5c @@ -0,0 +1,7 @@ +<?php + +interface autoload_interface { + function testFunction(); +} + +?>
\ No newline at end of file diff --git a/ext/standard/tests/serialize/bug14293.phpt b/ext/standard/tests/serialize/bug14293.phpt new file mode 100644 index 0000000..3fca7e4 --- /dev/null +++ b/ext/standard/tests/serialize/bug14293.phpt @@ -0,0 +1,36 @@ +--TEST-- +Bug #14293 (serialize() and __sleep()) +--FILE-- +<?php +class t +{ + function t() + { + $this->a = 'hello'; + } + + function __sleep() + { + echo "__sleep called\n"; + return array('a','b'); + } +} + +$t = new t(); +$data = serialize($t); +echo "$data\n"; +$t = unserialize($data); +var_dump($t); + +?> +--EXPECTF-- +__sleep called + +Notice: serialize(): "b" returned as member variable from __sleep() but does not exist in %sbug14293.php on line %d +O:1:"t":2:{s:1:"a";s:5:"hello";s:1:"b";N;} +object(t)#%d (2) { + ["a"]=> + string(5) "hello" + ["b"]=> + NULL +} diff --git a/ext/standard/tests/serialize/bug21957.phpt b/ext/standard/tests/serialize/bug21957.phpt new file mode 100644 index 0000000..29eeb2e --- /dev/null +++ b/ext/standard/tests/serialize/bug21957.phpt @@ -0,0 +1,49 @@ +--TEST-- +Bug #21957 (serialize() mangles objects with __sleep) +--FILE-- +<?php +class test +{ + public $a, $b; + + function test() + { + $this->a = 7; + $this->b = 2; + } + + function __sleep() + { + $this->b = 0; + } +} + +$t['one'] = 'ABC'; +$t['two'] = new test(); + +var_dump($t); + +$s = @serialize($t); +echo $s . "\n"; + +var_dump(unserialize($s)); +?> +--EXPECT-- +array(2) { + ["one"]=> + string(3) "ABC" + ["two"]=> + object(test)#1 (2) { + ["a"]=> + int(7) + ["b"]=> + int(2) + } +} +a:2:{s:3:"one";s:3:"ABC";s:3:"two";N;} +array(2) { + ["one"]=> + string(3) "ABC" + ["two"]=> + NULL +} diff --git a/ext/standard/tests/serialize/bug23298.phpt b/ext/standard/tests/serialize/bug23298.phpt new file mode 100644 index 0000000..a5305cf --- /dev/null +++ b/ext/standard/tests/serialize/bug23298.phpt @@ -0,0 +1,13 @@ +--TEST-- +Bug #23298 (serialize() and floats/doubles) +--INI-- +serialize_precision=100 +--FILE-- +<?php + ini_set('precision', 12); + $foo = 1.428571428571428647642857142; + $bar = unserialize(serialize($foo)); + var_dump(($foo === $bar)); +?> +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/serialize/bug24063.phpt b/ext/standard/tests/serialize/bug24063.phpt new file mode 100644 index 0000000..3cca101 --- /dev/null +++ b/ext/standard/tests/serialize/bug24063.phpt @@ -0,0 +1,23 @@ +--TEST-- +Bug #24063 (serialize() missing 0 after the . on scientific notation) +--INI-- +serialize_precision=100 +precision=12 +--FILE-- +<?php +$v = 1; +for ($i = 1; $i < 10; $i++) { + $v /= 10; + echo "{$v} ".unserialize(serialize($v))."\n"; +} +?> +--EXPECT-- +0.1 0.1 +0.01 0.01 +0.001 0.001 +0.0001 0.0001 +1.0E-5 1.0E-5 +1.0E-6 1.0E-6 +1.0E-7 1.0E-7 +1.0E-8 1.0E-8 +1.0E-9 1.0E-9 diff --git a/ext/standard/tests/serialize/bug25378.phpt b/ext/standard/tests/serialize/bug25378.phpt new file mode 100644 index 0000000..e865b96 --- /dev/null +++ b/ext/standard/tests/serialize/bug25378.phpt @@ -0,0 +1,59 @@ +--TEST-- +Bug #25378 (unserialize() crashes with invalid data) +--FILE-- +<?php +var_dump(unserialize("s:-1:\"\";")); +var_dump(unserialize("i:823")); +var_dump(unserialize("O:8:\"stdClass :0:{}")); +var_dump(unserialize("O:8:\"stdClass\"+0:{}")); +var_dump(unserialize("O:1000:\"stdClass\":0:{}")); +var_dump(unserialize("a:2:{i:0;s:2:\"12\":")); +var_dump(unserialize("a:2:{i:0;s:2:\"12\";i:1;s:3000:\"123")); +var_dump(unserialize("a:2:{i:0;s:2:\"12\"+i:1;s:3:\"123\";}")); +var_dump(unserialize("a:2:{i:0;s:2:\"12\";i:1;s:3:\"123\";")); +var_dump(unserialize("s:3000:\"123\";")); +var_dump(unserialize("s:3000:\"123")); +var_dump(unserialize("s:3:\"123;")); +var_dump(unserialize("s:0:\"123\";")); +?> +===DONE=== +--EXPECTF-- +Notice: unserialize(): Error at offset 0 of 8 bytes in %sbug25378.php on line %d +bool(false) + +Notice: unserialize(): Error at offset 0 of 5 bytes in %sbug25378.php on line %d +bool(false) + +Notice: unserialize(): Error at offset 13 of 19 bytes in %sbug25378.php on line %d +bool(false) + +Notice: unserialize(): Error at offset 14 of 19 bytes in %sbug25378.php on line %d +bool(false) + +Notice: unserialize(): Error at offset 2 of 22 bytes in %sbug25378.php on line %d +bool(false) + +Notice: unserialize(): Error at offset 17 of 18 bytes in %sbug25378.php on line %d +bool(false) + +Notice: unserialize(): Error at offset 24 of 33 bytes in %sbug25378.php on line %d +bool(false) + +Notice: unserialize(): Error at offset 17 of 33 bytes in %sbug25378.php on line %d +bool(false) + +Notice: unserialize(): Error at offset 33 of 32 bytes in %sbug25378.php on line %d +bool(false) + +Notice: unserialize(): Error at offset 2 of 13 bytes in %sbug25378.php on line %d +bool(false) + +Notice: unserialize(): Error at offset 2 of 11 bytes in %sbug25378.php on line %d +bool(false) + +Notice: unserialize(): Error at offset 8 of 9 bytes in %sbug25378.php on line %d +bool(false) + +Notice: unserialize(): Error at offset 5 of 10 bytes in %sbug25378.php on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/serialize/bug26762.phpt b/ext/standard/tests/serialize/bug26762.phpt new file mode 100644 index 0000000..3011bb6 --- /dev/null +++ b/ext/standard/tests/serialize/bug26762.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #26762 (unserialize() produces lowercase classnames) +--SKIPIF-- +<?php + if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); + if (class_exists('autoload_root')) die('skip Autoload test classes exist already'); +?> +--FILE-- +<?php + +ini_set('unserialize_callback_func','check'); + +function check($name) { + var_dump($name); + throw new exception; +} + +try { + @unserialize('O:3:"FOO":0:{}'); +} +catch (Exception $e) { + /* ignore */ +} + +?> +--EXPECTF-- +string(3) "FOO" diff --git a/ext/standard/tests/serialize/bug27469.phpt b/ext/standard/tests/serialize/bug27469.phpt new file mode 100644 index 0000000..e8d1410 --- /dev/null +++ b/ext/standard/tests/serialize/bug27469.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #27469 (serialize() objects of incomplete class) +--FILE-- +<?php +$str = 'O:9:"TestClass":0:{}'; +$obj = unserialize($str); +var_dump($obj); +echo serialize($obj)."\n"; +var_dump($obj); +echo serialize($obj)."\n"; +var_dump($obj); +?> +--EXPECT-- +object(__PHP_Incomplete_Class)#1 (1) { + ["__PHP_Incomplete_Class_Name"]=> + string(9) "TestClass" +} +O:9:"TestClass":0:{} +object(__PHP_Incomplete_Class)#1 (1) { + ["__PHP_Incomplete_Class_Name"]=> + string(9) "TestClass" +} +O:9:"TestClass":0:{} +object(__PHP_Incomplete_Class)#1 (1) { + ["__PHP_Incomplete_Class_Name"]=> + string(9) "TestClass" +} diff --git a/ext/standard/tests/serialize/bug28325.phpt b/ext/standard/tests/serialize/bug28325.phpt new file mode 100644 index 0000000..ee0e60e --- /dev/null +++ b/ext/standard/tests/serialize/bug28325.phpt @@ -0,0 +1,30 @@ +--TEST-- +Bug #28325 (Problem in serialisation of circular references) +--FILE-- +<?php +class a { + public $b; +} +class b { + public $c; +} +class c { + public $d; +} +$a = new a(); +$a->b = new b(); +$a->b->c = new c(); +$a->b->c->d = $a; +var_dump(unserialize(serialize($a))); +?> +--EXPECTF-- +object(a)#%d (1) { + ["b"]=> + object(b)#%d (1) { + ["c"]=> + object(c)#%d (1) { + ["d"]=> + *RECURSION* + } + } +} diff --git a/ext/standard/tests/serialize/bug30234.phpt b/ext/standard/tests/serialize/bug30234.phpt new file mode 100644 index 0000000..9b40cc5 --- /dev/null +++ b/ext/standard/tests/serialize/bug30234.phpt @@ -0,0 +1,40 @@ +--TEST-- +Bug #30234 (__autoload() not invoked for interfaces) +--SKIPIF-- +<?php + if (class_exists('autoload_root', false)) die('skip Autoload test classes exist already'); +?> +--FILE-- +<?php + +function __autoload($class_name) +{ + require_once(dirname(__FILE__) . '/' . strtolower($class_name) . '.p5c'); + echo __FUNCTION__ . '(' . $class_name . ")\n"; +} + +var_dump(interface_exists('autoload_interface', false)); +var_dump(class_exists('autoload_implements', false)); + +$o = unserialize('O:19:"Autoload_Implements":0:{}'); + +var_dump($o); +var_dump($o instanceof autoload_interface); +unset($o); + +var_dump(interface_exists('autoload_interface', false)); +var_dump(class_exists('autoload_implements', false)); + +?> +===DONE=== +--EXPECTF-- +bool(false) +bool(false) +__autoload(autoload_interface) +__autoload(Autoload_Implements) +object(autoload_implements)#%d (0) { +} +bool(true) +bool(true) +bool(true) +===DONE=== diff --git a/ext/standard/tests/serialize/bug31402.phpt b/ext/standard/tests/serialize/bug31402.phpt new file mode 100644 index 0000000..59cc52f --- /dev/null +++ b/ext/standard/tests/serialize/bug31402.phpt @@ -0,0 +1,87 @@ +--TEST-- +Bug #31402 (unserialize() generates references when it should not) +--INI-- +error_reporting=E_ALL&~E_STRICT&~E_DEPRECATED +--FILE-- +<?php + +class TestX { + var $i; + + function __construct($i) { + $this->i = $i; + } +} + +class TestY { + var $A = array(); + var $B; + + function __construct() { + $this->A[1] = new TestX(1); + $this->A[2] = & new TestX(2); + $this->A[3] = & $this->A[2]; + $this->B = $this->A[1]; + } +} + +$before = new TestY(); +$ser = serialize($before); +$after = unserialize($ser); + +var_dump($before, $after); + +?> +===DONE=== +--EXPECTF-- +object(TestY)#%d (2) { + ["A"]=> + array(3) { + [1]=> + object(TestX)#%d (1) { + ["i"]=> + int(1) + } + [2]=> + &object(TestX)#%d (1) { + ["i"]=> + int(2) + } + [3]=> + &object(TestX)#%d (1) { + ["i"]=> + int(2) + } + } + ["B"]=> + object(TestX)#%d (1) { + ["i"]=> + int(1) + } +} +object(TestY)#%d (2) { + ["A"]=> + array(3) { + [1]=> + object(TestX)#%d (1) { + ["i"]=> + int(1) + } + [2]=> + &object(TestX)#%d (1) { + ["i"]=> + int(2) + } + [3]=> + &object(TestX)#%d (1) { + ["i"]=> + int(2) + } + } + ["B"]=> + object(TestX)#%d (1) { + ["i"]=> + int(1) + } +} +===DONE=== diff --git a/ext/standard/tests/serialize/bug31442.phpt b/ext/standard/tests/serialize/bug31442.phpt new file mode 100644 index 0000000..6d451ba --- /dev/null +++ b/ext/standard/tests/serialize/bug31442.phpt @@ -0,0 +1,10 @@ +--TEST-- +Bug #31442 (unserialize broken on 64-bit systems) +--INI-- +precision=14 +--FILE-- +<?php +echo unserialize(serialize(2147483648)); +?> +--EXPECT-- +2147483648 diff --git a/ext/standard/tests/serialize/bug35895.phpt b/ext/standard/tests/serialize/bug35895.phpt new file mode 100644 index 0000000..22fce0d --- /dev/null +++ b/ext/standard/tests/serialize/bug35895.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #35895 (__sleep and private property) +--FILE-- +<?php +class Parents { + private $parents; + public function __sleep() { + return array("parents"); + } +} + +class Child extends Parents { + private $child; + public function __sleep() { + return array_merge(array("child"), parent::__sleep()); + } +} + +$obj = new Child(); +serialize($obj); + +?> +--EXPECTF-- +Notice: serialize(): "parents" returned as member variable from __sleep() but does not exist in %sbug35895.php on line %d diff --git a/ext/standard/tests/serialize/bug36424.phpt b/ext/standard/tests/serialize/bug36424.phpt new file mode 100644 index 0000000..c62be01 --- /dev/null +++ b/ext/standard/tests/serialize/bug36424.phpt @@ -0,0 +1,72 @@ +--TEST-- +Bug #36424 - Serializable interface breaks object references +--FILE-- +<?php + +echo "-TEST\n"; + +class a implements Serializable { + function serialize() { + return serialize(get_object_vars($this)); + } + function unserialize($s) { + foreach (unserialize($s) as $p=>$v) { + $this->$p=$v; + } + } +} +class b extends a {} +class c extends b {} + +$c = new c; +$c->a = new a; +$c->a->b = new b; +$c->a->b->c = $c; +$c->a->c = $c; +$c->a->b->a = $c->a; +$c->a->a = $c->a; + +$s = serialize($c); +printf("%s\n", $s); + +$d = unserialize($s); + +var_dump( + $d === $d->a->b->c, + $d->a->a === $d->a, + $d->a->b->a === $d->a, + $d->a->c === $d +); + +print_r($d); + +echo "Done\n"; + +?> +--EXPECTF-- +%aTEST +C:1:"c":108:{a:1:{s:1:"a";C:1:"a":81:{a:3:{s:1:"b";C:1:"b":30:{a:2:{s:1:"c";r:1;s:1:"a";r:3;}}s:1:"c";r:1;s:1:"a";r:3;}}}} +bool(true) +bool(true) +bool(true) +bool(true) +c Object +( + [a] => a Object + ( + [b] => b Object + ( + [c] => c Object + *RECURSION* + [a] => a Object + *RECURSION* + ) + + [c] => c Object + *RECURSION* + [a] => a Object + *RECURSION* + ) + +) +Done diff --git a/ext/standard/tests/serialize/bug37947.phpt b/ext/standard/tests/serialize/bug37947.phpt new file mode 100644 index 0000000..07371d1 --- /dev/null +++ b/ext/standard/tests/serialize/bug37947.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #37947 (zend_ptr_stack reallocation problem) +--INI-- +error_reporting=0 +--FILE-- +<?php +class test { + function extend_zend_ptr_stack($count,$a,$b,$c,$d,$e) { + if ($count>0) $this->extend_zend_ptr_stack($count - +1,$a,$b,$c,$d,$e); + } + + function __wakeup() { + $this->extend_zend_ptr_stack(10,'a','b','c','d','e'); + } +} + +$str='a:2:{i:0;O:4:"test":0:{}junk'; +var_dump(unserialize($str)); +--EXPECT-- +bool(false) diff --git a/ext/standard/tests/serialize/bug42919.phpt b/ext/standard/tests/serialize/bug42919.phpt new file mode 100644 index 0000000..0a3d0b2 --- /dev/null +++ b/ext/standard/tests/serialize/bug42919.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug #42919 (Unserializing of namespaced class object fails) +--FILE-- +<?php +namespace Foo; +class Bar { +} +echo serialize(new Bar) . "\n"; +$x = unserialize(serialize(new Bar)); +echo get_class($x) . "\n"; +?> +--EXPECT-- +O:7:"Foo\Bar":0:{} +Foo\Bar diff --git a/ext/standard/tests/serialize/bug43614.phpt b/ext/standard/tests/serialize/bug43614.phpt new file mode 100644 index 0000000..68568a1 --- /dev/null +++ b/ext/standard/tests/serialize/bug43614.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #43614 (incorrect processing of numerical string keys of array in arbitrary serialized data) +--FILE-- +<?php + +error_reporting(E_ALL); + +var_dump($a = unserialize('a:2:{s:2:"10";i:1;s:2:"01";i:2;}')); +var_dump($a['10']); +var_dump($a[b'01']); + +?> +--EXPECT-- +array(2) { + [10]=> + int(1) + ["01"]=> + int(2) +} +int(1) +int(2) diff --git a/ext/standard/tests/serialize/bug45706.phpt b/ext/standard/tests/serialize/bug45706.phpt new file mode 100644 index 0000000..218cdcc --- /dev/null +++ b/ext/standard/tests/serialize/bug45706.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bug #45706 Unserialization of classes derived from ArrayIterator fails +--FILE-- +<?php +class Foo1 extends ArrayIterator +{ +} +class Foo2 { +} +$x = array(new Foo1(),new Foo2); +$s = serialize($x); +$s = str_replace("Foo", "Bar", $s); +$y = unserialize($s); +var_dump($y); +--EXPECTF-- +Warning: Class __PHP_Incomplete_Class has no unserializer in %sbug45706.php on line %d +array(2) { + [0]=> + object(__PHP_Incomplete_Class)#%d (1) { + ["__PHP_Incomplete_Class_Name"]=> + string(4) "Bar1" + } + [1]=> + object(__PHP_Incomplete_Class)#%d (1) { + ["__PHP_Incomplete_Class_Name"]=> + string(4) "Bar2" + } +} diff --git a/ext/standard/tests/serialize/bug46882.phpt b/ext/standard/tests/serialize/bug46882.phpt new file mode 100644 index 0000000..cc64c64 --- /dev/null +++ b/ext/standard/tests/serialize/bug46882.phpt @@ -0,0 +1,8 @@ +--TEST-- +Bug #46882 (Serialize / Unserialize misbehaviour under OS with different bit numbers) +--FILE-- +<?php +var_dump(unserialize('i:5000000000;') == 5000000000); +?> +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/serialize/bug55798.phpt b/ext/standard/tests/serialize/bug55798.phpt new file mode 100644 index 0000000..df8443b --- /dev/null +++ b/ext/standard/tests/serialize/bug55798.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #55798 (serialize followed by unserialize with numeric object prop. gives integer prop) +--FILE-- +<?php + +$a = new stdClass(); +$a->{0} = 'X'; +$a->{1} = 'Y'; +var_dump(serialize($a)); +var_dump($a->{0}); +$b = unserialize(serialize($a)); +var_dump(serialize($b)); +var_dump($b->{0}); +--EXPECT-- +string(51) "O:8:"stdClass":2:{s:1:"0";s:1:"X";s:1:"1";s:1:"Y";}" +string(1) "X" +string(51) "O:8:"stdClass":2:{s:1:"0";s:1:"X";s:1:"1";s:1:"Y";}" +string(1) "X" diff --git a/ext/standard/tests/serialize/bug62373.phpt b/ext/standard/tests/serialize/bug62373.phpt new file mode 100644 index 0000000..666c33e --- /dev/null +++ b/ext/standard/tests/serialize/bug62373.phpt @@ -0,0 +1,25 @@ +--TEST-- +Bug #62373 (serialize() generates wrong reference to the object) +--FILE-- +<?php +class A {} +class B {} + +$size_of_ce = (((int)(log(PHP_INT_MAX) / log(2)) + 1 == 32 ? 368: 680) + 15) & ~15; +$dummy = array(); +$b = new B(); +$period = $size_of_ce << 5; +for ($i = 0; $i < $period * 3; $i++) { + $a = new A(); + $s = unserialize(serialize(array($b, $a))); + if ($s[0] === $s[1]) { + echo "OOPS\n"; + break; + } + $dummy[] = $a; +} + +echo "OK\n"; +?> +--EXPECT-- +OK diff --git a/ext/standard/tests/serialize/bug62836_1.phpt b/ext/standard/tests/serialize/bug62836_1.phpt new file mode 100644 index 0000000..7291046 --- /dev/null +++ b/ext/standard/tests/serialize/bug62836_1.phpt @@ -0,0 +1,34 @@ +--TEST-- +Bug #62836 (Seg fault or broken object references on unserialize()) +--FILE-- +<?php +$serialized_object='O:1:"A":4:{s:1:"b";O:1:"B":0:{}s:2:"b1";r:2;s:1:"c";O:1:"B":0:{}s:2:"c1";r:4;}'; +function __autoload($name) { + unserialize("i:4;"); + eval("class $name {} "); +} + +print_r(unserialize($serialized_object)); +echo "okey"; +?> +--EXPECT-- +A Object +( + [b] => B Object + ( + ) + + [b1] => B Object + ( + ) + + [c] => B Object + ( + ) + + [c1] => B Object + ( + ) + +) +okey diff --git a/ext/standard/tests/serialize/bug62836_2.phpt b/ext/standard/tests/serialize/bug62836_2.phpt new file mode 100644 index 0000000..0634b1d --- /dev/null +++ b/ext/standard/tests/serialize/bug62836_2.phpt @@ -0,0 +1,37 @@ +--TEST-- +Bug #62836 (Seg fault or broken object references on unserialize()) +--FILE-- +<?php +$serialized_object='O:1:"A":4:{s:1:"b";O:1:"B":0:{}s:2:"b1";r:2;s:1:"c";O:1:"B":0:{}s:2:"c1";r:4;}'; + +ini_set('unserialize_callback_func','mycallback'); + +function mycallback($classname) { + unserialize("i:4;"); + eval ("class $classname {} "); +} + +print_r(unserialize($serialized_object)); +echo "okey"; +?> +--EXPECT-- +A Object +( + [b] => B Object + ( + ) + + [b1] => B Object + ( + ) + + [c] => B Object + ( + ) + + [c1] => B Object + ( + ) + +) +okey diff --git a/ext/standard/tests/serialize/incomplete_class.phpt b/ext/standard/tests/serialize/incomplete_class.phpt new file mode 100644 index 0000000..8280485 --- /dev/null +++ b/ext/standard/tests/serialize/incomplete_class.phpt @@ -0,0 +1,27 @@ +--TEST-- +(un)serializing __PHP_Incomplete_Class instance +--FILE-- +<?php + +$d = serialize(new __PHP_Incomplete_Class); +$o = unserialize($d); +var_dump($o); + +$o->test = "a"; +var_dump($o->test); +var_dump($o->test2); + +echo "Done\n"; +?> +--EXPECTF-- +object(__PHP_Incomplete_Class)#%d (0) { +} + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "unknown" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line %d + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "unknown" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line %d +NULL + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "unknown" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line %d +NULL +Done diff --git a/ext/standard/tests/serialize/precision.phpt b/ext/standard/tests/serialize/precision.phpt new file mode 100644 index 0000000..142b2ce --- /dev/null +++ b/ext/standard/tests/serialize/precision.phpt @@ -0,0 +1,49 @@ +--TEST-- +Default precision is sufficient to serialize all the information in floats +--SKIPIF-- +<?php +if (pack('s', 1) != "\x01\x00") + die("skip test for little-endian architectures"); +--FILE-- +<?php + +$numbers = array( + "0000000000000000", //0 + "2d431cebe2362a3f", //.0002 + "2e431cebe2362a3f", //.0002 + 10^-Accuracy[.0002]*1.01 + "0000000000001000", //2^-1022. (minimum normal double) + "0100000000001000", //2^-1022. + 10^-Accuracy[2^-1022.]*1.01 + "ffffffffffffef7f", //2^1024. (maximum normal double) + "feffffffffffef7f", //2^1024. - 10^-Accuracy[2^1024.] + "0100000000000000", //minumum subnormal double + "0200000000000000", //2nd minumum subnormal double + "fffffffffffff000", //maximum subnormal double + "fefffffffffff000", //2nd maximum subnormal double + "0000000000000f7f", //+inf + "0000000000000fff", //-inf +); + +foreach ($numbers as $ns) { + $num = unpack("d", pack("H*", $ns)); $num = reset($num); + echo "number: ", sprintf("%.17e", $num), "... "; + $num2 = unserialize(serialize($num)); + $repr = unpack("H*", pack("d", $num2)); $repr = reset($repr); + if ($repr == $ns) + echo "OK\n"; + else + echo "mismatch\n\twas: $ns\n\tbecame: $repr\n"; +} +--EXPECT-- +number: 0.00000000000000000e+0... OK +number: 2.00000000000000010e-4... OK +number: 2.00000000000000037e-4... OK +number: 2.22507385850720138e-308... OK +number: 2.22507385850720188e-308... OK +number: 1.79769313486231571e+308... OK +number: 1.79769313486231551e+308... OK +number: 4.94065645841246544e-324... OK +number: 9.88131291682493088e-324... OK +number: 3.87340857288933536e-304... OK +number: 3.87340857288933455e-304... OK +number: 1.06293653832877718e+304... OK +number: -1.06293653832877718e+304... OK diff --git a/ext/standard/tests/serialize/serialization_arrays_001.phpt b/ext/standard/tests/serialize/serialization_arrays_001.phpt new file mode 100644 index 0000000..51acfc4 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_arrays_001.phpt @@ -0,0 +1,91 @@ +--TEST-- +Test serialize() & unserialize() functions: arrays (circular references) +--INI-- +serialize_precision=100 +--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--- Testing Circular reference of an array ---\n"; + +echo "-- Normal array --\n"; +$arr_circ = array(0, 1, -2, 3.333333, "a", array(), &$arr_circ); +$serialize_data = serialize($arr_circ); +var_dump( $serialize_data ); +$arr_circ = unserialize($serialize_data); +var_dump( $arr_circ ); + +echo "\n-- Associative array --\n"; +$arr_asso = array("a" => "test"); +$arr_asso[ "b" ] = &$arr_asso[ "a" ]; +var_dump($arr_asso); +$serialize_data = serialize($arr_asso); +var_dump($serialize_data); +$arr_asso = unserialize($serialize_data); +var_dump($arr_asso); + +echo "\nDone"; +?> +--EXPECTF-- +--- Testing Circular reference of an array --- +-- Normal array -- +string(238) "a:7:{i:0;i:0;i:1;i:1;i:2;i:-2;i:3;d:3.333333000000000101437080957111902534961700439453125;i:4;s:1:"a";i:5;a:0:{}i:6;a:7:{i:0;i:0;i:1;i:1;i:2;i:-2;i:3;d:3.333333000000000101437080957111902534961700439453125;i:4;s:1:"a";i:5;a:0:{}i:6;R:8;}}" +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-2) + [3]=> + float(3.333333) + [4]=> + string(1) "a" + [5]=> + array(0) { + } + [6]=> + &array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-2) + [3]=> + float(3.333333) + [4]=> + string(1) "a" + [5]=> + array(0) { + } + [6]=> + *RECURSION* + } +} + +-- Associative array -- +array(2) { + ["a"]=> + &string(4) "test" + ["b"]=> + &string(4) "test" +} +string(37) "a:2:{s:1:"a";s:4:"test";s:1:"b";R:2;}" +array(2) { + ["a"]=> + &string(4) "test" + ["b"]=> + &string(4) "test" +} + +Done diff --git a/ext/standard/tests/serialize/serialization_arrays_002.phpt b/ext/standard/tests/serialize/serialization_arrays_002.phpt new file mode 100644 index 0000000..f8cef78 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_arrays_002.phpt @@ -0,0 +1,544 @@ +--TEST-- +serialization: arrays with references amonst elements +--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: + */ + +function check(&$a) { + var_dump($a); + $ser = serialize($a); + var_dump($ser); + + $b = unserialize($ser); + var_dump($b); + $b[0] = "b0.changed"; + var_dump($b); + $b[1] = "b1.changed"; + var_dump($b); + $b[2] = "b2.changed"; + var_dump($b); +} + +echo "\n\n--- No references:\n"; +$a = array(); +$a[0] = 1; +$a[1] = 1; +$a[2] = 1; +check($a); + +echo "\n\n--- 0 refs 1:\n"; +$a = array(); +$a[0] = &$a[1]; +$a[1] = 1; +$a[2] = 1; +check($a); + +echo "\n\n--- 0 refs 2:\n"; +$a = array(); +$a[0] = &$a[2]; +$a[1] = 1; +$a[2] = 1; +check($a); + +echo "\n\n--- 1 refs 0:\n"; +$a = array(); +$a[0] = 1; +$a[1] = &$a[0]; +$a[2] = 1; +check($a); + +echo "\n\n--- 1 refs 2:\n"; +$a = array(); +$a[0] = 1; +$a[1] = &$a[2]; +$a[2] = 1; +check($a); + +echo "\n\n--- 2 refs 0:\n"; +$a = array(); +$a[0] = 1; +$a[1] = 1; +$a[2] = &$a[0]; +check($a); + +echo "\n\n--- 2 refs 1:\n"; +$a = array(); +$a[0] = 1; +$a[1] = 1; +$a[2] = &$a[1]; +check($a); + +echo "\n\n--- 0,1 ref 2:\n"; +$a = array(); +$a[0] = &$a[2]; +$a[1] = &$a[2]; +$a[2] = 1; +check($a); + +echo "\n\n--- 0,2 ref 1:\n"; +$a = array(); +$a[0] = &$a[1]; +$a[1] = 1; +$a[2] = &$a[1]; +check($a); + +echo "\n\n--- 1,2 ref 0:\n"; +$a = array(); +$a[0] = 1; +$a[1] = &$a[0]; +$a[2] = &$a[0]; +check($a); + +echo "Done"; +?> +--EXPECTF-- + + +--- No references: +array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) +} +string(30) "a:3:{i:0;i:1;i:1;i:1;i:2;i:1;}" +array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + string(10) "b2.changed" +} + + +--- 0 refs 1: +array(3) { + [1]=> + &int(1) + [0]=> + &int(1) + [2]=> + int(1) +} +string(30) "a:3:{i:1;i:1;i:0;R:2;i:2;i:1;}" +array(3) { + [1]=> + &int(1) + [0]=> + &int(1) + [2]=> + int(1) +} +array(3) { + [1]=> + &string(10) "b0.changed" + [0]=> + &string(10) "b0.changed" + [2]=> + int(1) +} +array(3) { + [1]=> + &string(10) "b1.changed" + [0]=> + &string(10) "b1.changed" + [2]=> + int(1) +} +array(3) { + [1]=> + &string(10) "b1.changed" + [0]=> + &string(10) "b1.changed" + [2]=> + string(10) "b2.changed" +} + + +--- 0 refs 2: +array(3) { + [2]=> + &int(1) + [0]=> + &int(1) + [1]=> + int(1) +} +string(30) "a:3:{i:2;i:1;i:0;R:2;i:1;i:1;}" +array(3) { + [2]=> + &int(1) + [0]=> + &int(1) + [1]=> + int(1) +} +array(3) { + [2]=> + &string(10) "b0.changed" + [0]=> + &string(10) "b0.changed" + [1]=> + int(1) +} +array(3) { + [2]=> + &string(10) "b0.changed" + [0]=> + &string(10) "b0.changed" + [1]=> + string(10) "b1.changed" +} +array(3) { + [2]=> + &string(10) "b2.changed" + [0]=> + &string(10) "b2.changed" + [1]=> + string(10) "b1.changed" +} + + +--- 1 refs 0: +array(3) { + [0]=> + &int(1) + [1]=> + &int(1) + [2]=> + int(1) +} +string(30) "a:3:{i:0;i:1;i:1;R:2;i:2;i:1;}" +array(3) { + [0]=> + &int(1) + [1]=> + &int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + &string(10) "b0.changed" + [2]=> + int(1) +} +array(3) { + [0]=> + &string(10) "b1.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + int(1) +} +array(3) { + [0]=> + &string(10) "b1.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + string(10) "b2.changed" +} + + +--- 1 refs 2: +array(3) { + [0]=> + int(1) + [2]=> + &int(1) + [1]=> + &int(1) +} +string(30) "a:3:{i:0;i:1;i:2;i:1;i:1;R:3;}" +array(3) { + [0]=> + int(1) + [2]=> + &int(1) + [1]=> + &int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [2]=> + &int(1) + [1]=> + &int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [2]=> + &string(10) "b1.changed" + [1]=> + &string(10) "b1.changed" +} +array(3) { + [0]=> + string(10) "b0.changed" + [2]=> + &string(10) "b2.changed" + [1]=> + &string(10) "b2.changed" +} + + +--- 2 refs 0: +array(3) { + [0]=> + &int(1) + [1]=> + int(1) + [2]=> + &int(1) +} +string(30) "a:3:{i:0;i:1;i:1;i:1;i:2;R:2;}" +array(3) { + [0]=> + &int(1) + [1]=> + int(1) + [2]=> + &int(1) +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + int(1) + [2]=> + &string(10) "b0.changed" +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + &string(10) "b0.changed" +} +array(3) { + [0]=> + &string(10) "b2.changed" + [1]=> + string(10) "b1.changed" + [2]=> + &string(10) "b2.changed" +} + + +--- 2 refs 1: +array(3) { + [0]=> + int(1) + [1]=> + &int(1) + [2]=> + &int(1) +} +string(30) "a:3:{i:0;i:1;i:1;i:1;i:2;R:3;}" +array(3) { + [0]=> + int(1) + [1]=> + &int(1) + [2]=> + &int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + &int(1) + [2]=> + &int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + &string(10) "b1.changed" +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + &string(10) "b2.changed" + [2]=> + &string(10) "b2.changed" +} + + +--- 0,1 ref 2: +array(3) { + [2]=> + &int(1) + [0]=> + &int(1) + [1]=> + &int(1) +} +string(30) "a:3:{i:2;i:1;i:0;R:2;i:1;R:2;}" +array(3) { + [2]=> + &int(1) + [0]=> + &int(1) + [1]=> + &int(1) +} +array(3) { + [2]=> + &string(10) "b0.changed" + [0]=> + &string(10) "b0.changed" + [1]=> + &string(10) "b0.changed" +} +array(3) { + [2]=> + &string(10) "b1.changed" + [0]=> + &string(10) "b1.changed" + [1]=> + &string(10) "b1.changed" +} +array(3) { + [2]=> + &string(10) "b2.changed" + [0]=> + &string(10) "b2.changed" + [1]=> + &string(10) "b2.changed" +} + + +--- 0,2 ref 1: +array(3) { + [1]=> + &int(1) + [0]=> + &int(1) + [2]=> + &int(1) +} +string(30) "a:3:{i:1;i:1;i:0;R:2;i:2;R:2;}" +array(3) { + [1]=> + &int(1) + [0]=> + &int(1) + [2]=> + &int(1) +} +array(3) { + [1]=> + &string(10) "b0.changed" + [0]=> + &string(10) "b0.changed" + [2]=> + &string(10) "b0.changed" +} +array(3) { + [1]=> + &string(10) "b1.changed" + [0]=> + &string(10) "b1.changed" + [2]=> + &string(10) "b1.changed" +} +array(3) { + [1]=> + &string(10) "b2.changed" + [0]=> + &string(10) "b2.changed" + [2]=> + &string(10) "b2.changed" +} + + +--- 1,2 ref 0: +array(3) { + [0]=> + &int(1) + [1]=> + &int(1) + [2]=> + &int(1) +} +string(30) "a:3:{i:0;i:1;i:1;R:2;i:2;R:2;}" +array(3) { + [0]=> + &int(1) + [1]=> + &int(1) + [2]=> + &int(1) +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + &string(10) "b0.changed" + [2]=> + &string(10) "b0.changed" +} +array(3) { + [0]=> + &string(10) "b1.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + &string(10) "b1.changed" +} +array(3) { + [0]=> + &string(10) "b2.changed" + [1]=> + &string(10) "b2.changed" + [2]=> + &string(10) "b2.changed" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_arrays_003.phpt b/ext/standard/tests/serialize/serialization_arrays_003.phpt new file mode 100644 index 0000000..8d664fc --- /dev/null +++ b/ext/standard/tests/serialize/serialization_arrays_003.phpt @@ -0,0 +1,294 @@ +--TEST-- +serialization: arrays with references to an external variable +--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: + */ + +function check(&$a) { + var_dump($a); + $ser = serialize($a); + var_dump($ser); + + $b = unserialize($ser); + var_dump($b); + $b[0] = "b0.changed"; + var_dump($b); + $b[1] = "b1.changed"; + var_dump($b); + $b[2] = "b2.changed"; + var_dump($b); +} + +echo "\n\n--- 0 refs external:\n"; +$ext = 1; +$a = array(); +$a[0] = &$ext; +$a[1] = 1; +$a[2] = 1; +check($a); + +echo "\n\n--- 1 refs external:\n"; +$ext = 1; +$a = array(); +$a[0] = 1; +$a[1] = &$ext; +$a[2] = 1; +check($a); + +echo "\n\n--- 2 refs external:\n"; +$ext = 1; +$a = array(); +$a[0] = 1; +$a[1] = 1; +$a[2] = &$ext; +check($a); + +echo "\n\n--- 1,2 ref external:\n"; +$ext = 1; +$a = array(); +$a[0] = &$ext; +$a[1] = &$ext; +$a[2] = 1; +check($a); + +echo "\n\n--- 1,2,3 ref external:\n"; +$ext = 1; +$a = array(); +$a[0] = &$ext; +$a[1] = &$ext; +$a[2] = &$ext; +check($a); + +echo "Done"; +?> +--EXPECTF-- + + +--- 0 refs external: +array(3) { + [0]=> + &int(1) + [1]=> + int(1) + [2]=> + int(1) +} +string(30) "a:3:{i:0;i:1;i:1;i:1;i:2;i:1;}" +array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + string(10) "b2.changed" +} + + +--- 1 refs external: +array(3) { + [0]=> + int(1) + [1]=> + &int(1) + [2]=> + int(1) +} +string(30) "a:3:{i:0;i:1;i:1;i:1;i:2;i:1;}" +array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + string(10) "b2.changed" +} + + +--- 2 refs external: +array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + &int(1) +} +string(30) "a:3:{i:0;i:1;i:1;i:1;i:2;i:1;}" +array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + string(10) "b2.changed" +} + + +--- 1,2 ref external: +array(3) { + [0]=> + &int(1) + [1]=> + &int(1) + [2]=> + int(1) +} +string(30) "a:3:{i:0;i:1;i:1;R:2;i:2;i:1;}" +array(3) { + [0]=> + &int(1) + [1]=> + &int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + &string(10) "b0.changed" + [2]=> + int(1) +} +array(3) { + [0]=> + &string(10) "b1.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + int(1) +} +array(3) { + [0]=> + &string(10) "b1.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + string(10) "b2.changed" +} + + +--- 1,2,3 ref external: +array(3) { + [0]=> + &int(1) + [1]=> + &int(1) + [2]=> + &int(1) +} +string(30) "a:3:{i:0;i:1;i:1;R:2;i:2;R:2;}" +array(3) { + [0]=> + &int(1) + [1]=> + &int(1) + [2]=> + &int(1) +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + &string(10) "b0.changed" + [2]=> + &string(10) "b0.changed" +} +array(3) { + [0]=> + &string(10) "b1.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + &string(10) "b1.changed" +} +array(3) { + [0]=> + &string(10) "b2.changed" + [1]=> + &string(10) "b2.changed" + [2]=> + &string(10) "b2.changed" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_arrays_004.phpt b/ext/standard/tests/serialize/serialization_arrays_004.phpt new file mode 100644 index 0000000..55d849c --- /dev/null +++ b/ext/standard/tests/serialize/serialization_arrays_004.phpt @@ -0,0 +1,269 @@ +--TEST-- +serialization: arrays with references to the containing array +--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: + */ + +function check(&$a) { + var_dump($a); + $ser = serialize($a); + var_dump($ser); + + $b = unserialize($ser); + var_dump($b); + $b[0] = "b0.changed"; + var_dump($b); + $b[1] = "b1.changed"; + var_dump($b); + $b[2] = "b2.changed"; + var_dump($b); +} + +echo "\n\n--- 1 refs container:\n"; +$a = array(); +$a[0] = &$a; +$a[1] = 1; +$a[2] = 1; +check($a); + +echo "\n\n--- 1,2 ref container:\n"; +$a = array(); +$a[0] = &$a; +$a[1] = &$a; +$a[2] = 1; +check($a); + +echo "\n\n--- 1,2,3 ref container:\n"; +$a = array(); +$a[0] = &$a; +$a[1] = &$a; +$a[2] = &$a; +check($a); + +echo "Done"; +?> +--EXPECTF-- +--- 1 refs container: +array(3) { + [0]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + int(1) + [2]=> + int(1) + } + [1]=> + int(1) + [2]=> + int(1) +} +string(56) "a:3:{i:0;a:3:{i:0;R:2;i:1;i:1;i:2;i:1;}i:1;i:1;i:2;i:1;}" +array(3) { + [0]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + int(1) + [2]=> + int(1) + } + [1]=> + int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + string(10) "b2.changed" +} + + +--- 1,2 ref container: +array(3) { + [0]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + int(1) + } + [1]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + int(1) + } + [2]=> + int(1) +} +string(56) "a:3:{i:0;a:3:{i:0;R:2;i:1;R:2;i:2;i:1;}i:1;R:2;i:2;i:1;}" +array(3) { + [0]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + int(1) + } + [1]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + int(1) + } + [2]=> + int(1) +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + &string(10) "b0.changed" + [2]=> + int(1) +} +array(3) { + [0]=> + &string(10) "b1.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + int(1) +} +array(3) { + [0]=> + &string(10) "b1.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + string(10) "b2.changed" +} + + +--- 1,2,3 ref container: +array(3) { + [0]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } + [1]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } + [2]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } +} +string(56) "a:3:{i:0;a:3:{i:0;R:2;i:1;R:2;i:2;R:2;}i:1;R:2;i:2;R:2;}" +array(3) { + [0]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } + [1]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } + [2]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + &string(10) "b0.changed" + [2]=> + &string(10) "b0.changed" +} +array(3) { + [0]=> + &string(10) "b1.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + &string(10) "b1.changed" +} +array(3) { + [0]=> + &string(10) "b2.changed" + [1]=> + &string(10) "b2.changed" + [2]=> + &string(10) "b2.changed" +} +Done diff --git a/ext/standard/tests/serialize/serialization_arrays_005.phpt b/ext/standard/tests/serialize/serialization_arrays_005.phpt new file mode 100644 index 0000000..10e3312 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_arrays_005.phpt @@ -0,0 +1,521 @@ +--TEST-- +serialization: arrays with references, nested +--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: + */ + +function check(&$a) { + var_dump($a); + $ser = serialize($a); + var_dump($ser); + + $b = unserialize($ser); + + // Change each element and dump result. + foreach($b as $k=>$v) { + if (is_array($v)){ + foreach($b[$k] as $sk=>$sv) { + $b[$k][$sk] = "b$k.$sk.changed"; + var_dump($b); + } + } else { + $b[$k] = "b$k.changed"; + var_dump($b); + } + } +} + +echo "\n\n--- Nested array references 1 element in containing array:\n"; +$a = array(); +$c = array(1,1,&$a); +$a[0] = &$c[0]; +$a[1] = 1; +check($c); + +echo "\n\n--- Nested array references 1 element in containing array (slightly different):\n"; +$a = array(); +$c = array(1,&$a,1); +$a[0] = 1; +$a[1] = &$c[0]; +check($c); + +echo "\n\n--- Nested array references 2 elements in containing array:\n"; +$a = array(); +$c = array(1,1,&$a); +$a[0] = &$c[0]; +$a[1] = &$c[1]; +check($c); + + +echo "\n\n--- Containing array references 1 element in nested array:\n"; +$a = array(); +$a[0] = 1; +$a[1] = 1; +$c = array(1,&$a[0],&$a); +check($c); + +echo "\n\n--- Containing array references 2 elements in nested array:\n"; +$a = array(); +$a[0] = 1; +$a[1] = 1; +$c = array(&$a[0],&$a[1],&$a); +check($c); + +echo "\n\n--- Nested array references container:\n"; +$a = array(); +$c = array(1,1,&$a); +$a[0] = 1; +$a[1] = &$c; +check($c); + +?> +--EXPECTF-- +--- Nested array references 1 element in containing array: +array(3) { + [0]=> + &int(1) + [1]=> + int(1) + [2]=> + &array(2) { + [0]=> + &int(1) + [1]=> + int(1) + } +} +string(48) "a:3:{i:0;i:1;i:1;i:1;i:2;a:2:{i:0;R:2;i:1;i:1;}}" +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + int(1) + [2]=> + array(2) { + [0]=> + &string(10) "b0.changed" + [1]=> + int(1) + } +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + array(2) { + [0]=> + &string(10) "b0.changed" + [1]=> + int(1) + } +} +array(3) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + array(2) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + int(1) + } +} +array(3) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + array(2) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + string(12) "b2.1.changed" + } +} + + +--- Nested array references 1 element in containing array (slightly different): +array(3) { + [0]=> + &int(1) + [1]=> + &array(2) { + [0]=> + int(1) + [1]=> + &int(1) + } + [2]=> + int(1) +} +string(48) "a:3:{i:0;i:1;i:1;a:2:{i:0;i:1;i:1;R:2;}i:2;i:1;}" +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + &string(10) "b0.changed" + } + [2]=> + int(1) +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + array(2) { + [0]=> + string(12) "b1.0.changed" + [1]=> + &string(10) "b0.changed" + } + [2]=> + int(1) +} +array(3) { + [0]=> + &string(12) "b1.1.changed" + [1]=> + array(2) { + [0]=> + string(12) "b1.0.changed" + [1]=> + &string(12) "b1.1.changed" + } + [2]=> + int(1) +} +array(3) { + [0]=> + &string(12) "b1.1.changed" + [1]=> + array(2) { + [0]=> + string(12) "b1.0.changed" + [1]=> + &string(12) "b1.1.changed" + } + [2]=> + string(10) "b2.changed" +} + + +--- Nested array references 2 elements in containing array: +array(3) { + [0]=> + &int(1) + [1]=> + &int(1) + [2]=> + &array(2) { + [0]=> + &int(1) + [1]=> + &int(1) + } +} +string(48) "a:3:{i:0;i:1;i:1;i:1;i:2;a:2:{i:0;R:2;i:1;R:3;}}" +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + &int(1) + [2]=> + array(2) { + [0]=> + &string(10) "b0.changed" + [1]=> + &int(1) + } +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + array(2) { + [0]=> + &string(10) "b0.changed" + [1]=> + &string(10) "b1.changed" + } +} +array(3) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + array(2) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + &string(10) "b1.changed" + } +} +array(3) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + &string(12) "b2.1.changed" + [2]=> + array(2) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + &string(12) "b2.1.changed" + } +} + + +--- Containing array references 1 element in nested array: +array(3) { + [0]=> + int(1) + [1]=> + &int(1) + [2]=> + &array(2) { + [0]=> + &int(1) + [1]=> + int(1) + } +} +string(48) "a:3:{i:0;i:1;i:1;i:1;i:2;a:2:{i:0;R:3;i:1;i:1;}}" +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + &int(1) + [2]=> + array(2) { + [0]=> + &int(1) + [1]=> + int(1) + } +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + array(2) { + [0]=> + &string(10) "b1.changed" + [1]=> + int(1) + } +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + &string(12) "b2.0.changed" + [2]=> + array(2) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + int(1) + } +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + &string(12) "b2.0.changed" + [2]=> + array(2) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + string(12) "b2.1.changed" + } +} + + +--- Containing array references 2 elements in nested array: +array(3) { + [0]=> + &int(1) + [1]=> + &int(1) + [2]=> + &array(2) { + [0]=> + &int(1) + [1]=> + &int(1) + } +} +string(48) "a:3:{i:0;i:1;i:1;i:1;i:2;a:2:{i:0;R:2;i:1;R:3;}}" +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + &int(1) + [2]=> + array(2) { + [0]=> + &string(10) "b0.changed" + [1]=> + &int(1) + } +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + array(2) { + [0]=> + &string(10) "b0.changed" + [1]=> + &string(10) "b1.changed" + } +} +array(3) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + array(2) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + &string(10) "b1.changed" + } +} +array(3) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + &string(12) "b2.1.changed" + [2]=> + array(2) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + &string(12) "b2.1.changed" + } +} + + +--- Nested array references container: +array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + &array(2) { + [0]=> + int(1) + [1]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + *RECURSION* + } + } +} +string(74) "a:3:{i:0;i:1;i:1;i:1;i:2;a:2:{i:0;i:1;i:1;a:3:{i:0;i:1;i:1;i:1;i:2;R:4;}}}" +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + int(1) + [2]=> + &array(2) { + [0]=> + int(1) + [1]=> + array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + *RECURSION* + } + } +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + &array(2) { + [0]=> + int(1) + [1]=> + array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + *RECURSION* + } + } +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + &array(2) { + [0]=> + string(12) "b2.0.changed" + [1]=> + array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + *RECURSION* + } + } +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + &array(2) { + [0]=> + string(12) "b2.0.changed" + [1]=> + string(12) "b2.1.changed" + } +} diff --git a/ext/standard/tests/serialize/serialization_error_001.phpt b/ext/standard/tests/serialize/serialization_error_001.phpt new file mode 100644 index 0000000..da6f50c --- /dev/null +++ b/ext/standard/tests/serialize/serialization_error_001.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test serialize() & unserialize() functions: error conditions - wrong number of args. +--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 "*** Testing serialize()/unserialize() : error conditions ***\n"; + +// Zero arguments +var_dump( serialize() ); +var_dump( unserialize() ); + +//Test serialize with one more than the expected number of arguments +var_dump( serialize(1,2) ); +var_dump( unserialize(1,2) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing serialize()/unserialize() : error conditions *** + +Warning: serialize() expects exactly 1 parameter, 0 given in %s on line 16 +NULL + +Warning: unserialize() expects exactly 1 parameter, 0 given in %s on line 17 +bool(false) + +Warning: serialize() expects exactly 1 parameter, 2 given in %s on line 20 +NULL + +Warning: unserialize() expects exactly 1 parameter, 2 given in %s on line 21 +bool(false) +Done diff --git a/ext/standard/tests/serialize/serialization_miscTypes_001.phpt b/ext/standard/tests/serialize/serialization_miscTypes_001.phpt Binary files differnew file mode 100644 index 0000000..548a673 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_miscTypes_001.phpt diff --git a/ext/standard/tests/serialize/serialization_objects_001.phpt b/ext/standard/tests/serialize/serialization_objects_001.phpt Binary files differnew file mode 100644 index 0000000..f85b89e --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_001.phpt diff --git a/ext/standard/tests/serialize/serialization_objects_002.phpt b/ext/standard/tests/serialize/serialization_objects_002.phpt Binary files differnew file mode 100644 index 0000000..fbd9e26 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_002.phpt diff --git a/ext/standard/tests/serialize/serialization_objects_003.phpt b/ext/standard/tests/serialize/serialization_objects_003.phpt new file mode 100644 index 0000000..2313ffa --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_003.phpt @@ -0,0 +1,69 @@ +--TEST-- +Test serialize() & unserialize() functions: objects (abstract classes) +--INI-- +serialize_precision=100 +--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--- Testing Abstract Class ---\n"; +// abstract class +abstract class Name +{ + public function Name() { + $this->a = 10; + $this->b = 12.222; + $this->c = "string"; + } + abstract protected function getClassName(); + public function printClassName () { + return $this->getClassName(); + } +} +// implement abstract class +class extendName extends Name +{ + var $a, $b, $c; + + protected function getClassName() { + return "extendName"; + } +} + +$obj_extendName = new extendName(); +$serialize_data = serialize($obj_extendName); +var_dump( $serialize_data ); +$unserialize_data = unserialize($serialize_data); +var_dump( $unserialize_data ); + +$serialize_data = serialize($obj_extendName->printClassName()); +var_dump( $serialize_data ); +$unserialize_data = unserialize($serialize_data); +var_dump( $unserialize_data ); + +echo "\nDone"; +?> +--EXPECTF-- +--- Testing Abstract Class --- +string(119) "O:10:"extendName":3:{s:1:"a";i:10;s:1:"b";d:12.2219999999999995310417943983338773250579833984375;s:1:"c";s:6:"string";}" +object(extendName)#%d (3) { + ["a"]=> + int(10) + ["b"]=> + float(12.222) + ["c"]=> + string(6) "string" +} +string(18) "s:10:"extendName";" +string(10) "extendName" + +Done diff --git a/ext/standard/tests/serialize/serialization_objects_004.phpt b/ext/standard/tests/serialize/serialization_objects_004.phpt new file mode 100644 index 0000000..6b826a3 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_004.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test serialize() & unserialize() functions: objects - ensure that COW references of objects are not serialized separately (unlike other types). +--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: + */ + +$x = new stdClass; +$ref = &$x; +var_dump(serialize(array($x, $x))); + +$x = 1; +$ref = &$x; +var_dump(serialize(array($x, $x))); + +$x = "a"; +$ref = &$x; +var_dump(serialize(array($x, $x))); + +$x = true; +$ref = &$x; +var_dump(serialize(array($x, $x))); + +$x = null; +$ref = &$x; +var_dump(serialize(array($x, $x))); + +$x = array(); +$ref = &$x; +var_dump(serialize(array($x, $x))); + +echo "Done"; +?> +--EXPECTF-- +string(37) "a:2:{i:0;O:8:"stdClass":0:{}i:1;r:2;}" +string(22) "a:2:{i:0;i:1;i:1;i:1;}" +string(30) "a:2:{i:0;s:1:"a";i:1;s:1:"a";}" +string(22) "a:2:{i:0;b:1;i:1;b:1;}" +string(18) "a:2:{i:0;N;i:1;N;}" +string(26) "a:2:{i:0;a:0:{}i:1;a:0:{}}" +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_objects_005.phpt b/ext/standard/tests/serialize/serialization_objects_005.phpt new file mode 100644 index 0000000..35b1593 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_005.phpt @@ -0,0 +1,120 @@ +--TEST-- +Check behaviour of incomplete class +--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: + */ + +$serialized = 'O:1:"C":1:{s:1:"p";i:1;}'; + +$incomplete = unserialize($serialized); +eval('Class C {}'); +$complete = unserialize($serialized); + + +echo "\n\n---> Various types of access on complete class:\n" ; +var_dump($complete); +var_dump(is_object($complete)); +var_dump($complete->p); + +$ref1 = "ref1.original"; +$complete->p = &$ref1; +var_dump($complete->p); +$ref1 = "ref1.changed"; +var_dump($complete->p); +$complete->p = "p.changed"; +var_dump($ref1); + +var_dump(isset($complete->x)); +$complete->x = "x.new"; +var_dump(isset($complete->x)); +unset($complete->x); +var_dump($complete->x); + + +echo "\n\n---> Same types of access on incomplete class:\n" ; +var_dump($incomplete); +var_dump(is_object($incomplete)); +var_dump($incomplete->p); + +$ref2 = "ref1.original"; +$incomplete->p = &$ref2; +var_dump($incomplete->p); +$ref2 = "ref1.changed"; +var_dump($incomplete->p); +$incomplete->p = "p.changed"; +var_dump($ref1); + +var_dump(isset($incomplete->x)); +$incomplete->x = "x.new"; +var_dump(isset($incomplete->x)); +unset($incomplete->x); +var_dump($incomplete->x); + +$incomplete->f(); + +echo "Done"; +?> +--EXPECTF-- +---> Various types of access on complete class: +object(C)#%d (1) { + ["p"]=> + int(1) +} +bool(true) +int(1) +string(13) "ref1.original" +string(12) "ref1.changed" +string(9) "p.changed" +bool(false) +bool(true) + +Notice: Undefined property: C::$x in %s on line 37 +NULL + + +---> Same types of access on incomplete class: +object(__PHP_Incomplete_Class)#%d (2) { + ["__PHP_Incomplete_Class_Name"]=> + string(1) "C" + ["p"]=> + int(1) +} +bool(false) + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 43 +NULL + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 46 + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 47 +NULL + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 49 +NULL + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 50 +string(9) "p.changed" + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 53 +bool(false) + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 54 + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 55 +bool(false) + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 56 + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 57 +NULL + +Fatal error: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 59
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_objects_006.phpt b/ext/standard/tests/serialize/serialization_objects_006.phpt new file mode 100644 index 0000000..e223f4e --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_006.phpt @@ -0,0 +1,28 @@ +--TEST-- +Behaviour of incomplete class is preserved even when it was not created by unserialize(). +--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: + */ + +$a = new __PHP_Incomplete_Class; +var_dump($a); +var_dump($a->p); + +echo "Done"; +?> +--EXPECTF-- +object(__PHP_Incomplete_Class)#%d (0) { +} + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "unknown" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 15 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_objects_007.phpt b/ext/standard/tests/serialize/serialization_objects_007.phpt new file mode 100644 index 0000000..9cba9d1 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_007.phpt @@ -0,0 +1,42 @@ +--TEST-- +Ensure __autoload is called twice if unserialize_callback_func is defined. +--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: + */ + +function __autoload($name) { + echo "in __autoload($name)\n"; +} + +ini_set('unserialize_callback_func','check'); + +function check($name) { + echo "in check($name)\n"; +} + +$o = unserialize('O:3:"FOO":0:{}'); + +var_dump($o); + +echo "Done"; +?> +--EXPECTF-- +in __autoload(FOO) +in check(FOO) +in __autoload(FOO) + +Warning: unserialize(): Function check() hasn't defined the class it was called for in %s on line 23 +object(__PHP_Incomplete_Class)#%d (1) { + ["__PHP_Incomplete_Class_Name"]=> + string(3) "FOO" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_objects_008.phpt b/ext/standard/tests/serialize/serialization_objects_008.phpt new file mode 100644 index 0000000..b963872 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_008.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bad unserialize_callback_func +--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: + */ + +ini_set('unserialize_callback_func','Nonexistent'); +$o = unserialize('O:3:"FOO":0:{}'); +var_dump($o); +echo "Done"; +?> +--EXPECTF-- + +Warning: unserialize(): defined (Nonexistent) but not found in %s on line 14 +object(__PHP_Incomplete_Class)#%d (1) { + ["__PHP_Incomplete_Class_Name"]=> + string(3) "FOO" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_objects_009.phpt b/ext/standard/tests/serialize/serialization_objects_009.phpt new file mode 100644 index 0000000..595692d --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_009.phpt @@ -0,0 +1,35 @@ +--TEST-- +Custom unserialization of classes with no custom unserializer. +--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: + */ + +$ser = 'C:1:"C":6:{dasdas}'; +$a = unserialize($ser); +eval('class C {}'); +$b = unserialize($ser); + +var_dump($a, $b); + +echo "Done"; +?> +--EXPECTF-- +Warning: Class __PHP_Incomplete_Class has no unserializer in %sserialization_objects_009.php on line %d + +Warning: Class C has no unserializer in %sserialization_objects_009.php on line %d +object(__PHP_Incomplete_Class)#%d (1) { + ["__PHP_Incomplete_Class_Name"]=> + string(1) "C" +} +object(C)#%d (0) { +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_objects_010.phpt b/ext/standard/tests/serialize/serialization_objects_010.phpt new file mode 100644 index 0000000..0fbf072 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_010.phpt @@ -0,0 +1,37 @@ +--TEST-- +Serialize() must return a string or NULL +--SKIPIF-- +<?php if (!interface_exists('Serializable')) die('skip Interface Serialzable not defined'); ?> +--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: + */ + +Class C implements Serializable { + public function serialize() { + return $this; + } + + public function unserialize($blah) { + } +} + +try { + var_dump(serialize(new C)); +} catch (Exception $e) { + echo $e->getMessage(). "\n"; +} + +echo "Done"; +?> +--EXPECTF-- +C::serialize() must return a string or NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_objects_011.phpt b/ext/standard/tests/serialize/serialization_objects_011.phpt new file mode 100644 index 0000000..1dc4839 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_011.phpt @@ -0,0 +1,196 @@ +--TEST-- +Object serialization / unserialization with inherited and hidden properties. +--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: + */ + +Class A { + private $APriv = "A.APriv"; + protected $AProt = "A.AProt"; + public $APub = "A.APub"; + + function audit() { + return isset($this->APriv, $this->AProt, $this->APub); + } +} + +Class B extends A { + private $BPriv = "B.BPriv"; + protected $BProt = "B.BProt"; + public $BPub = "B.BPub"; + + function audit() { + return parent::audit() && isset($this->AProt, $this->APub, + $this->BPriv, $this->BProt, $this->BPub); + } +} + +Class C extends B { + private $APriv = "C.APriv"; + protected $AProt = "C.AProt"; + public $APub = "C.APub"; + + private $CPriv = "C.CPriv"; + protected $CProt = "C.BProt"; + public $CPub = "C.CPub"; + + function audit() { + return parent::audit() && isset($this->APriv, $this->AProt, $this->APub, + $this->BProt, $this->BPub, + $this->CPriv, $this->CProt, $this->CPub); + } +} + +function prettyPrint($obj) { + echo "\n\nBefore serialization:\n"; + var_dump($obj); + + echo "Serialized form:\n"; + $ser = serialize($obj); + $serPrintable = str_replace("\0", '\0', $ser); + var_dump($serPrintable); + + echo "Unserialized:\n"; + $uobj = unserialize($ser); + var_dump($uobj); + + echo "Sanity check: "; + var_dump($uobj->audit()); +} + +echo "-- Test instance of A --\n"; +prettyPrint(new A); +echo "\n\n-- Test instance of B --\n"; +prettyPrint(new B); +echo "\n\n-- Test instance of C --\n"; +prettyPrint(new C); + +echo "Done"; +?> +--EXPECTF-- +-- Test instance of A -- + + +Before serialization: +object(A)#%d (3) { + ["APriv":"A":private]=> + string(7) "A.APriv" + ["AProt":protected]=> + string(7) "A.AProt" + ["APub"]=> + string(6) "A.APub" +} +Serialized form: +string(98) "O:1:"A":3:{s:8:"\0A\0APriv";s:7:"A.APriv";s:8:"\0*\0AProt";s:7:"A.AProt";s:4:"APub";s:6:"A.APub";}" +Unserialized: +object(A)#%d (3) { + ["APriv":"A":private]=> + string(7) "A.APriv" + ["AProt":protected]=> + string(7) "A.AProt" + ["APub"]=> + string(6) "A.APub" +} +Sanity check: bool(true) + + +-- Test instance of B -- + + +Before serialization: +object(B)#%d (6) { + ["BPriv":"B":private]=> + string(7) "B.BPriv" + ["BProt":protected]=> + string(7) "B.BProt" + ["BPub"]=> + string(6) "B.BPub" + ["APriv":"A":private]=> + string(7) "A.APriv" + ["AProt":protected]=> + string(7) "A.AProt" + ["APub"]=> + string(6) "A.APub" +} +Serialized form: +string(184) "O:1:"B":6:{s:8:"\0B\0BPriv";s:7:"B.BPriv";s:8:"\0*\0BProt";s:7:"B.BProt";s:4:"BPub";s:6:"B.BPub";s:8:"\0A\0APriv";s:7:"A.APriv";s:8:"\0*\0AProt";s:7:"A.AProt";s:4:"APub";s:6:"A.APub";}" +Unserialized: +object(B)#%d (6) { + ["BPriv":"B":private]=> + string(7) "B.BPriv" + ["BProt":protected]=> + string(7) "B.BProt" + ["BPub"]=> + string(6) "B.BPub" + ["APriv":"A":private]=> + string(7) "A.APriv" + ["AProt":protected]=> + string(7) "A.AProt" + ["APub"]=> + string(6) "A.APub" +} +Sanity check: bool(true) + + +-- Test instance of C -- + + +Before serialization: +object(C)#%d (10) { + ["APriv":"C":private]=> + string(7) "C.APriv" + ["AProt":protected]=> + string(7) "C.AProt" + ["APub"]=> + string(6) "C.APub" + ["CPriv":"C":private]=> + string(7) "C.CPriv" + ["CProt":protected]=> + string(7) "C.BProt" + ["CPub"]=> + string(6) "C.CPub" + ["BPriv":"B":private]=> + string(7) "B.BPriv" + ["BProt":protected]=> + string(7) "B.BProt" + ["BPub"]=> + string(6) "B.BPub" + ["APriv":"A":private]=> + string(7) "A.APriv" +} +Serialized form: +string(302) "O:1:"C":10:{s:8:"\0C\0APriv";s:7:"C.APriv";s:8:"\0*\0AProt";s:7:"C.AProt";s:4:"APub";s:6:"C.APub";s:8:"\0C\0CPriv";s:7:"C.CPriv";s:8:"\0*\0CProt";s:7:"C.BProt";s:4:"CPub";s:6:"C.CPub";s:8:"\0B\0BPriv";s:7:"B.BPriv";s:8:"\0*\0BProt";s:7:"B.BProt";s:4:"BPub";s:6:"B.BPub";s:8:"\0A\0APriv";s:7:"A.APriv";}" +Unserialized: +object(C)#%d (10) { + ["APriv":"C":private]=> + string(7) "C.APriv" + ["AProt":protected]=> + string(7) "C.AProt" + ["APub"]=> + string(6) "C.APub" + ["CPriv":"C":private]=> + string(7) "C.CPriv" + ["CProt":protected]=> + string(7) "C.BProt" + ["CPub"]=> + string(6) "C.CPub" + ["BPriv":"B":private]=> + string(7) "B.BPriv" + ["BProt":protected]=> + string(7) "B.BProt" + ["BPub"]=> + string(6) "B.BPub" + ["APriv":"A":private]=> + string(7) "A.APriv" +} +Sanity check: bool(true) +Done
\ No newline at end of file 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 diff --git a/ext/standard/tests/serialize/serialization_objects_013.phpt b/ext/standard/tests/serialize/serialization_objects_013.phpt new file mode 100644 index 0000000..01b623c --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_013.phpt @@ -0,0 +1,494 @@ +--TEST-- +Object serialization / unserialization: references amongst properties +--INI-- +error_reporting = E_ALL & ~E_STRICT +--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: + */ + +function check(&$obj) { + var_dump($obj); + $ser = serialize($obj); + var_dump($ser); + + $uobj = unserialize($ser); + var_dump($uobj); + $uobj->a = "obj->a.changed"; + var_dump($uobj); + $uobj->b = "obj->b.changed"; + var_dump($uobj); + $uobj->c = "obj->c.changed"; + var_dump($uobj); +} + +echo "\n\n--- a refs b:\n"; +$obj = new stdClass; +$obj->a = &$obj->b; +$obj->b = 1; +$obj->c = 1; +check($obj); + +echo "\n\n--- a refs c:\n"; +$obj = new stdClass; +$obj->a = &$obj->c; +$obj->b = 1; +$obj->c = 1; +check($obj); + +echo "\n\n--- b refs a:\n"; +$obj = new stdClass; +$obj->a = 1; +$obj->b = &$obj->a; +$obj->c = 1; +check($obj); + +echo "\n\n--- b refs c:\n"; +$obj = new stdClass; +$obj->a = 1; +$obj->b = &$obj->c; +$obj->c = 1; +check($obj); + +echo "\n\n--- c refs a:\n"; +$obj = new stdClass; +$obj->a = 1; +$obj->b = 1; +$obj->c = &$obj->a; +check($obj); + +echo "\n\n--- c refs b:\n"; +$obj = new stdClass; +$obj->a = 1; +$obj->b = 1; +$obj->c = &$obj->b; +check($obj); + +echo "\n\n--- a,b refs c:\n"; +$obj = new stdClass; +$obj->a = &$obj->c; +$obj->b = &$obj->c; +$obj->c = 1; +check($obj); + +echo "\n\n--- a,c refs b:\n"; +$obj = new stdClass; +$obj->a = &$obj->b; +$obj->b = 1; +$obj->c = &$obj->b; +check($obj); + +echo "\n\n--- b,c refs a:\n"; +$obj = new stdClass; +$obj->a = 1; +$obj->b = &$obj->a; +$obj->c = &$obj->a; +check($obj); + +echo "Done"; +?> +--EXPECTF-- + +--- a refs b: +object(stdClass)#%d (3) { + ["b"]=> + &int(1) + ["a"]=> + &int(1) + ["c"]=> + int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"b";i:1;s:1:"a";R:2;s:1:"c";i:1;}" +object(stdClass)#%d (3) { + ["b"]=> + &int(1) + ["a"]=> + &int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["b"]=> + &string(14) "obj->a.changed" + ["a"]=> + &string(14) "obj->a.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["b"]=> + &string(14) "obj->b.changed" + ["a"]=> + &string(14) "obj->b.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["b"]=> + &string(14) "obj->b.changed" + ["a"]=> + &string(14) "obj->b.changed" + ["c"]=> + string(14) "obj->c.changed" +} + + +--- a refs c: +object(stdClass)#%d (3) { + ["c"]=> + &int(1) + ["a"]=> + &int(1) + ["b"]=> + int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"c";i:1;s:1:"a";R:2;s:1:"b";i:1;}" +object(stdClass)#%d (3) { + ["c"]=> + &int(1) + ["a"]=> + &int(1) + ["b"]=> + int(1) +} +object(stdClass)#%d (3) { + ["c"]=> + &string(14) "obj->a.changed" + ["a"]=> + &string(14) "obj->a.changed" + ["b"]=> + int(1) +} +object(stdClass)#%d (3) { + ["c"]=> + &string(14) "obj->a.changed" + ["a"]=> + &string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" +} +object(stdClass)#%d (3) { + ["c"]=> + &string(14) "obj->c.changed" + ["a"]=> + &string(14) "obj->c.changed" + ["b"]=> + string(14) "obj->b.changed" +} + + +--- b refs a: +object(stdClass)#%d (3) { + ["a"]=> + &int(1) + ["b"]=> + &int(1) + ["c"]=> + int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";R:2;s:1:"c";i:1;}" +object(stdClass)#%d (3) { + ["a"]=> + &int(1) + ["b"]=> + &int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->a.changed" + ["b"]=> + &string(14) "obj->a.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->b.changed" + ["b"]=> + &string(14) "obj->b.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->b.changed" + ["b"]=> + &string(14) "obj->b.changed" + ["c"]=> + string(14) "obj->c.changed" +} + + +--- b refs c: +object(stdClass)#%d (3) { + ["a"]=> + int(1) + ["c"]=> + &int(1) + ["b"]=> + &int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"c";i:1;s:1:"b";R:3;}" +object(stdClass)#%d (3) { + ["a"]=> + int(1) + ["c"]=> + &int(1) + ["b"]=> + &int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["c"]=> + &int(1) + ["b"]=> + &int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["c"]=> + &string(14) "obj->b.changed" + ["b"]=> + &string(14) "obj->b.changed" +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["c"]=> + &string(14) "obj->c.changed" + ["b"]=> + &string(14) "obj->c.changed" +} + + +--- c refs a: +object(stdClass)#%d (3) { + ["a"]=> + &int(1) + ["b"]=> + int(1) + ["c"]=> + &int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";i:1;s:1:"c";R:2;}" +object(stdClass)#%d (3) { + ["a"]=> + &int(1) + ["b"]=> + int(1) + ["c"]=> + &int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->a.changed" + ["b"]=> + int(1) + ["c"]=> + &string(14) "obj->a.changed" +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + &string(14) "obj->a.changed" +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->c.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + &string(14) "obj->c.changed" +} + + +--- c refs b: +object(stdClass)#%d (3) { + ["a"]=> + int(1) + ["b"]=> + &int(1) + ["c"]=> + &int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";i:1;s:1:"c";R:3;}" +object(stdClass)#%d (3) { + ["a"]=> + int(1) + ["b"]=> + &int(1) + ["c"]=> + &int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + &int(1) + ["c"]=> + &int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + &string(14) "obj->b.changed" + ["c"]=> + &string(14) "obj->b.changed" +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + &string(14) "obj->c.changed" + ["c"]=> + &string(14) "obj->c.changed" +} + + +--- a,b refs c: +object(stdClass)#%d (3) { + ["c"]=> + &int(1) + ["a"]=> + &int(1) + ["b"]=> + &int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"c";i:1;s:1:"a";R:2;s:1:"b";R:2;}" +object(stdClass)#%d (3) { + ["c"]=> + &int(1) + ["a"]=> + &int(1) + ["b"]=> + &int(1) +} +object(stdClass)#%d (3) { + ["c"]=> + &string(14) "obj->a.changed" + ["a"]=> + &string(14) "obj->a.changed" + ["b"]=> + &string(14) "obj->a.changed" +} +object(stdClass)#%d (3) { + ["c"]=> + &string(14) "obj->b.changed" + ["a"]=> + &string(14) "obj->b.changed" + ["b"]=> + &string(14) "obj->b.changed" +} +object(stdClass)#%d (3) { + ["c"]=> + &string(14) "obj->c.changed" + ["a"]=> + &string(14) "obj->c.changed" + ["b"]=> + &string(14) "obj->c.changed" +} + + +--- a,c refs b: +object(stdClass)#%d (3) { + ["b"]=> + &int(1) + ["a"]=> + &int(1) + ["c"]=> + &int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"b";i:1;s:1:"a";R:2;s:1:"c";R:2;}" +object(stdClass)#%d (3) { + ["b"]=> + &int(1) + ["a"]=> + &int(1) + ["c"]=> + &int(1) +} +object(stdClass)#%d (3) { + ["b"]=> + &string(14) "obj->a.changed" + ["a"]=> + &string(14) "obj->a.changed" + ["c"]=> + &string(14) "obj->a.changed" +} +object(stdClass)#%d (3) { + ["b"]=> + &string(14) "obj->b.changed" + ["a"]=> + &string(14) "obj->b.changed" + ["c"]=> + &string(14) "obj->b.changed" +} +object(stdClass)#%d (3) { + ["b"]=> + &string(14) "obj->c.changed" + ["a"]=> + &string(14) "obj->c.changed" + ["c"]=> + &string(14) "obj->c.changed" +} + + +--- b,c refs a: +object(stdClass)#%d (3) { + ["a"]=> + &int(1) + ["b"]=> + &int(1) + ["c"]=> + &int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";R:2;s:1:"c";R:2;}" +object(stdClass)#%d (3) { + ["a"]=> + &int(1) + ["b"]=> + &int(1) + ["c"]=> + &int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->a.changed" + ["b"]=> + &string(14) "obj->a.changed" + ["c"]=> + &string(14) "obj->a.changed" +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->b.changed" + ["b"]=> + &string(14) "obj->b.changed" + ["c"]=> + &string(14) "obj->b.changed" +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->c.changed" + ["b"]=> + &string(14) "obj->c.changed" + ["c"]=> + &string(14) "obj->c.changed" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_objects_014.phpt b/ext/standard/tests/serialize/serialization_objects_014.phpt new file mode 100644 index 0000000..234f5e0 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_014.phpt @@ -0,0 +1,295 @@ +--TEST-- +Object serialization / unserialization: references to external values +--INI-- +error_reporting = E_ALL & ~E_STRICT +--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: + */ + +function check(&$obj) { + var_dump($obj); + $ser = serialize($obj); + var_dump($ser); + + $uobj = unserialize($ser); + var_dump($uobj); + $uobj->a = "obj->a.changed"; + var_dump($uobj); + $uobj->b = "obj->b.changed"; + var_dump($uobj); + $uobj->c = "obj->c.changed"; + var_dump($uobj); +} + +echo "\n\n--- a refs external:\n"; +$ext = 1; +$obj = new stdClass; +$obj->a = &$ext; +$obj->b = 1; +$obj->c = 1; +check($obj); + +echo "\n\n--- b refs external:\n"; +$ext = 1; +$obj = new stdClass; +$obj->a = 1; +$obj->b = &$ext; +$obj->c = 1; +check($obj); + +echo "\n\n--- c refs external:\n"; +$ext = 1; +$obj = new stdClass; +$obj->a = 1; +$obj->b = 1; +$obj->c = &$ext; +check($obj); + +echo "\n\n--- a,b ref external:\n"; +$ext = 1; +$obj = new stdClass; +$obj->a = &$ext; +$obj->b = &$ext; +$obj->c = 1; +check($obj); + +echo "\n\n--- a,b,c ref external:\n"; +$ext = 1; +$obj = new stdClass; +$obj->a = &$ext; +$obj->b = &$ext; +$obj->c = &$ext; +check($obj); + +echo "Done"; +?> +--EXPECTF-- + +--- a refs external: +object(stdClass)#%d (3) { + ["a"]=> + &int(1) + ["b"]=> + int(1) + ["c"]=> + int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";i:1;s:1:"c";i:1;}" +object(stdClass)#%d (3) { + ["a"]=> + int(1) + ["b"]=> + int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + string(14) "obj->c.changed" +} + + +--- b refs external: +object(stdClass)#%d (3) { + ["a"]=> + int(1) + ["b"]=> + &int(1) + ["c"]=> + int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";i:1;s:1:"c";i:1;}" +object(stdClass)#%d (3) { + ["a"]=> + int(1) + ["b"]=> + int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + string(14) "obj->c.changed" +} + + +--- c refs external: +object(stdClass)#%d (3) { + ["a"]=> + int(1) + ["b"]=> + int(1) + ["c"]=> + &int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";i:1;s:1:"c";i:1;}" +object(stdClass)#%d (3) { + ["a"]=> + int(1) + ["b"]=> + int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + string(14) "obj->c.changed" +} + + +--- a,b ref external: +object(stdClass)#%d (3) { + ["a"]=> + &int(1) + ["b"]=> + &int(1) + ["c"]=> + int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";R:2;s:1:"c";i:1;}" +object(stdClass)#%d (3) { + ["a"]=> + &int(1) + ["b"]=> + &int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->a.changed" + ["b"]=> + &string(14) "obj->a.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->b.changed" + ["b"]=> + &string(14) "obj->b.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->b.changed" + ["b"]=> + &string(14) "obj->b.changed" + ["c"]=> + string(14) "obj->c.changed" +} + + +--- a,b,c ref external: +object(stdClass)#%d (3) { + ["a"]=> + &int(1) + ["b"]=> + &int(1) + ["c"]=> + &int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";R:2;s:1:"c";R:2;}" +object(stdClass)#%d (3) { + ["a"]=> + &int(1) + ["b"]=> + &int(1) + ["c"]=> + &int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->a.changed" + ["b"]=> + &string(14) "obj->a.changed" + ["c"]=> + &string(14) "obj->a.changed" +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->b.changed" + ["b"]=> + &string(14) "obj->b.changed" + ["c"]=> + &string(14) "obj->b.changed" +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->c.changed" + ["b"]=> + &string(14) "obj->c.changed" + ["c"]=> + &string(14) "obj->c.changed" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_objects_015.phpt b/ext/standard/tests/serialize/serialization_objects_015.phpt new file mode 100644 index 0000000..2265cab --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_015.phpt @@ -0,0 +1,336 @@ +--TEST-- +Object serialization / unserialization: properties reference containing object +--INI-- +error_reporting = E_ALL & ~E_STRICT +--FILE-- +<?php + +function check(&$obj) { + var_dump($obj); + $ser = serialize($obj); + var_dump($ser); + + $uobj = unserialize($ser); + var_dump($uobj); + $uobj->a = "obj->a.changed"; + var_dump($uobj); + $uobj->b = "obj->b.changed"; + var_dump($uobj); + $uobj->c = "obj->c.changed"; + var_dump($uobj); +} + +echo "\n\n--- a refs container:\n"; +$ext = 1; +$obj = new stdClass; +$obj->a = &$obj; +$obj->b = 1; +$obj->c = 1; +check($obj); + +echo "\n\n--- a eqs container:\n"; +$ext = 1; +$obj = new stdClass; +$obj->a = $obj; +$obj->b = 1; +$obj->c = 1; +check($obj); + +echo "\n\n--- a,b ref container:\n"; +$ext = 1; +$obj = new stdClass; +$obj->a = &$obj; +$obj->b = &$obj; +$obj->c = 1; +check($obj); + +echo "\n\n--- a,b eq container:\n"; +$ext = 1; +$obj = new stdClass; +$obj->a = $obj; +$obj->b = $obj; +$obj->c = 1; +check($obj); + +echo "\n\n--- a,b,c ref container:\n"; +$ext = 1; +$obj = new stdClass; +$obj->a = &$obj; +$obj->b = &$obj; +$obj->c = &$obj; +check($obj); + +echo "\n\n--- a,b,c eq container:\n"; +$ext = 1; +$obj = new stdClass; +$obj->a = $obj; +$obj->b = $obj; +$obj->c = $obj; +check($obj); + +echo "Done"; +?> +--EXPECTF-- +--- a refs container: +object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + int(1) + ["c"]=> + int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";R:1;s:1:"b";i:1;s:1:"c";i:1;}" +object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + string(14) "obj->c.changed" +} + + +--- a eqs container: +object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + int(1) + ["c"]=> + int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";r:1;s:1:"b";i:1;s:1:"c";i:1;}" +object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + string(14) "obj->c.changed" +} + + +--- a,b ref container: +object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";R:1;s:1:"b";R:1;s:1:"c";i:1;}" +object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->a.changed" + ["b"]=> + &string(14) "obj->a.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->b.changed" + ["b"]=> + &string(14) "obj->b.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->b.changed" + ["b"]=> + &string(14) "obj->b.changed" + ["c"]=> + string(14) "obj->c.changed" +} + + +--- a,b eq container: +object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";r:1;s:1:"b";r:1;s:1:"c";i:1;}" +object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + *RECURSION* + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + string(14) "obj->c.changed" +} + + +--- a,b,c ref container: +object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + *RECURSION* +} +string(55) "O:8:"stdClass":3:{s:1:"a";R:1;s:1:"b";R:1;s:1:"c";R:1;}" +object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + *RECURSION* +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->a.changed" + ["b"]=> + &string(14) "obj->a.changed" + ["c"]=> + &string(14) "obj->a.changed" +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->b.changed" + ["b"]=> + &string(14) "obj->b.changed" + ["c"]=> + &string(14) "obj->b.changed" +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->c.changed" + ["b"]=> + &string(14) "obj->c.changed" + ["c"]=> + &string(14) "obj->c.changed" +} + + +--- a,b,c eq container: +object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + *RECURSION* +} +string(55) "O:8:"stdClass":3:{s:1:"a";r:1;s:1:"b";r:1;s:1:"c";r:1;}" +object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + *RECURSION* +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + *RECURSION* + ["c"]=> + *RECURSION* +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + *RECURSION* +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + string(14) "obj->c.changed" +} +Done diff --git a/ext/standard/tests/serialize/serialization_precision_001.phpt b/ext/standard/tests/serialize/serialization_precision_001.phpt new file mode 100644 index 0000000..eb633be --- /dev/null +++ b/ext/standard/tests/serialize/serialization_precision_001.phpt @@ -0,0 +1,21 @@ +--TEST-- +Test serialize_precision (part 1) +--INI-- +serialize_precision=10 +--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: + */ + +var_dump(serialize(0.1)); +?> +--EXPECTF-- +string(6) "d:0.1;"
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_precision_002.phpt b/ext/standard/tests/serialize/serialization_precision_002.phpt new file mode 100644 index 0000000..653fabe --- /dev/null +++ b/ext/standard/tests/serialize/serialization_precision_002.phpt @@ -0,0 +1,21 @@ +--TEST-- +Test serialize_precision (part 2) +--INI-- +serialize_precision=75 +--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: + */ + +var_dump(serialize(0.1)); +?> +--EXPECTF-- +string(60) "d:0.1000000000000000055511151231257827021181583404541015625;"
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_resources_001.phpt b/ext/standard/tests/serialize/serialization_resources_001.phpt new file mode 100644 index 0000000..dbb7d3d --- /dev/null +++ b/ext/standard/tests/serialize/serialization_resources_001.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test serialize() & unserialize() functions: resources +--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--- Testing Resource ---\n"; +$file_handle = fopen( __FILE__, "r" ); +$serialized_data = serialize( $file_handle ); +fclose($file_handle); +var_dump($serialized_data); +var_dump(unserialize($serialized_data)); + +echo "\nDone"; +?> +--EXPECTF-- +--- Testing Resource --- +string(4) "i:%d;" +int(%d) + +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/unserializeS.phpt b/ext/standard/tests/serialize/unserializeS.phpt new file mode 100644 index 0000000..897208b --- /dev/null +++ b/ext/standard/tests/serialize/unserializeS.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug MOPB-29 (wrong length calculation for S) +--INI-- +error_reporting=0 +--FILE-- +<?php +$str = 'S:'.(100*3).':"'.str_repeat('\61', 100).'"'; +$arr = array(str_repeat('"', 200)."1"=>1,str_repeat('"', 200)."2"=>1); + +$data = unserialize($str); +var_dump($data); + +--EXPECT-- +bool(false) |