PHP SplObjectStorage serialize() Function Last Updated : 23 Jun, 2023 Comments Improve Suggest changes Like Article Like Report 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 <?php // Create new storage class $str = new SplObjectStorage; $obj = new StdClass; $str->attach($obj, "GeeksforGeeks"); // Print serialize result echo $str->serialize(); ?> Output: x:i:1;O:8:"stdClass":0:{}, s:13:"GeeksforGeeks";;m:a:0:{} Program 2: php <?php $obj1 = new StdClass; $obj2 = new StdClass; // Create new storage class $gfg1 = new SplObjectStorage(); $gfg1[$obj1] = "Geeks"; // Create new storage class $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 Comment More infoAdvertise with us Next Article PHP SplObjectStorage serialize() Function R R_Raj Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP SplObjectStorage setInfo() Function The SplObjectStorage::setInfo() function is an inbuilt function in PHP which is used to set the data associated with the current iterator entry. Syntax: void SplObjectStorage::setInfo( $val ) Parameters: This function accepts a single parameter $val which specifies the data to be associate to the cu 1 min read PHP SplObjectStorage rewind() Function The SplObjectStorage::rewind() function is an inbuilt function in PHP which is used to rewind the iterator to the first storage element. Syntax: void SplObjectStorage::rewind() Parameters: This function does not accept any parameter. Return Value: This function does not return any value. Below progr 1 min read PHP SplObjectStorage removeAll() Function The SplObjectStorage::removeAll() function is an inbuilt function in PHP which is used to remove all objects contained in another storage from the current storage. Syntax: void SplObjectStorage::removeAll( $obj ) Parameters: This function accepts a single parameter $obj which specify the storage to 1 min read PHP SplObjectStorage key() Function The SplObjectStorage::key() function is an inbuilt function in PHP which is used to get the index of the currently pointing iterator. Syntax: int SplObjectStorage::key() Parameters: This function does not accept any parameter. Return Value: This function returns the index at which the iterator curre 1 min read PHP SplObjectStorage removeAllExcept() Function The SplObjectStorage::removeAllExcept() function is an inbuilt function in PHP which is used to remove all objects from storage except for those contains by another storage. Syntax: int SplObjectStorage::removeAllExcept() Parameters: This function accepts a single parameter $obj which specify object 1 min read Like