The SplObjectStorage::serialize() function is an inbuilt function in PHP which is used to serialize the result of the storage.
Syntax:
string SplObjectStorage::serialize()
Parameters: This function does not accept any parameter.
Return Value: This function returns a string which is the representation of the storage.
Below programs illustrate the SplObjectStorage::serialize() function in PHP:
Program 1:
<?php
$str = new SplObjectStorage;
$obj = new StdClass;
$str ->attach( $obj , "GeeksforGeeks" );
echo $str ->serialize();
?>
|
Output:
x:i:1;O:8:"stdClass":0:{}, s:13:"GeeksforGeeks";;m:a:0:{}
Program 2:
<?php
$obj1 = new StdClass;
$obj2 = new StdClass;
$gfg1 = new SplObjectStorage();
$gfg1 [ $obj1 ] = "Geeks" ;
$gfg2 = new SplObjectStorage();
$gfg2 [ $obj1 ] = "GFG" ;
$gfg2 [ $obj2 ] = "GeeksClasses" ;
print_r( $gfg1 ->serialize(). "\n" );
echo ( $gfg2 ->serialize(). "\n" );
?>
|
Output:
x:i:1;O:8:"stdClass":0:{}, s:5:"Geeks";;m:a:0:{}
x:i:2;O:8:"stdClass":0:{}, s:3:"GFG";;O:8:"stdClass":0:{}, s:12:"GeeksClasses";;m:a:0:{}
Reference: https://www.php.net/manual/en/splobjectstorage.serialize.php
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
23 Jun, 2023
Like Article
Save Article