mirror of
https://github.com/php/php-src.git
synced 2026-04-22 07:28:09 +02:00
d30cd7d7e7
Closes GH-5590
314 lines
7.0 KiB
PHP
314 lines
7.0 KiB
PHP
--TEST--
|
|
Test serialize() & unserialize() functions: objects (variations)
|
|
--INI--
|
|
serialize_precision=100
|
|
--FILE--
|
|
<?php
|
|
echo "\n--- Testing Variations in objects ---\n";
|
|
|
|
class members
|
|
{
|
|
private $var_private = 10;
|
|
protected $var_protected = "string";
|
|
public $var_public = array(-100.123, "string", TRUE);
|
|
}
|
|
|
|
class nomembers { }
|
|
|
|
class C {
|
|
var $a, $b, $c, $d, $e, $f, $g, $h;
|
|
function __construct() {
|
|
$this->a = 10;
|
|
$this->b = "string";
|
|
$this->c = TRUE;
|
|
$this->d = -2.34444;
|
|
$this->e = array(1, 2.22, "string", TRUE, array(),
|
|
new members(), null);
|
|
$this->f = new nomembers();
|
|
$this->g = $GLOBALS['file_handle'];
|
|
$this->h = NULL;
|
|
}
|
|
}
|
|
|
|
class D extends C {
|
|
function __construct( $w, $x, $y, $z ) {
|
|
$this->a = $w;
|
|
$this->b = $x;
|
|
$this->c = $y;
|
|
$this->d = $z;
|
|
}
|
|
}
|
|
|
|
$variation_obj_arr = array(
|
|
new C(),
|
|
new D( 1, 2, 3333, 444444 ),
|
|
new D( .5, 0.005, -1.345, 10.005e5 ),
|
|
new D( TRUE, true, FALSE, false ),
|
|
new D( "a", 'a', "string", 'string' ),
|
|
new D( array(),
|
|
array(1, 2.222, TRUE, FALSE, "string"),
|
|
array(new nomembers(), $file_handle, NULL, ""),
|
|
array(array(1,2,3,array()))
|
|
),
|
|
new D( NULL, null, "", "\0" ),
|
|
new D( new members, new nomembers, $file_handle, NULL),
|
|
);
|
|
|
|
/* Testing serialization on all the objects through loop */
|
|
foreach( $variation_obj_arr as $object) {
|
|
|
|
echo "After Serialization => ";
|
|
$serialize_data = serialize( $object );
|
|
var_dump( $serialize_data );
|
|
|
|
echo "After Unserialization => ";
|
|
$unserialize_data = unserialize( $serialize_data );
|
|
var_dump( $unserialize_data );
|
|
}
|
|
|
|
echo "\nDone";
|
|
?>
|
|
--EXPECTF--
|
|
--- Testing Variations in objects ---
|
|
|
|
Notice: Undefined array key "file_handle" in %s on line %d
|
|
|
|
Warning: Undefined variable $file_handle in %s on line %d
|
|
|
|
Warning: Undefined variable $file_handle in %s on line %d
|
|
After Serialization => string(493) "O:1:"C":8:{s:1:"a";i:10;s:1:"b";s:6:"string";s:1:"c";b:1;s:1:"d";d:-2.344440000000000079438677857979200780391693115234375;s:1:"e";a:7:{i:0;i:1;i:1;d:2.220000000000000195399252334027551114559173583984375;i:2;s:6:"string";i:3;b:1;i:4;a:0:{}i:5;O:7:"members":3:{s:20:" |