PHP SplObjectStorage unserialize() Function
Last Updated :
23 Jun, 2023
The SplObjectStorage::unserialize() function is an inbuilt function in PHP which is used to unserialize the storage from its serialize string representation.
Syntax:
void SplObjectStorage::unserialize( $serilize )
Parameters: This function accepts a single parameter $serialize which specifies the string serialization of the storage.
Return Value: This function does not return any value.
Below programs illustrate the SplObjectStorage::unserialize() function in PHP:
Program 1:
<?php
$obj1 = new StdClass;
$gfg1 = new SplObjectStorage();
$gfg1 [ $obj1 ] = "Geeks" ;
$gfg1 ->unserialize( $gfg1 ->serialize());
print_r( $gfg1 );
?>
|
Output:
SplObjectStorage Object
(
[storage:SplObjectStorage:private] => Array
(
[00000000494fcd4d000000001f544823] => Array
(
[obj] => stdClass Object
(
)
[inf] => Geeks
)
[00000000494fcd4f000000001f544823] => Array
(
[obj] => stdClass Object
(
)
[inf] => Geeks
)
)
)
Program 2:
<?php
$obj1 = new StdClass;
$obj2 = new StdClass;
$gfg1 = new SplObjectStorage();
$gfg1 [ $obj1 ] = "Geeks" ;
$gfg2 = new SplObjectStorage();
$gfg2 [ $obj1 ] = "GFG" ;
$gfg2 [ $obj2 ] = "GeeksClasses" ;
$gfg1 ->unserialize( $gfg2 ->serialize());
var_dump( count ( $gfg1 ));
$gfg2 ->unserialize( $gfg1 ->serialize());
var_dump( count ( $gfg2 ));
?>
|
Reference: https://www.php.net/manual/en/splobjectstorage.unserialize.php
Share your thoughts in the comments
Please Login to comment...