PHP | SplObjectStorage serialize() Function
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 // Create new storage class $str = new SplObjectStorage; $obj = new StdClass; $str->attach($obj, "GeeksforGeeks"); // Print serialize result echo $str->serialize(); ?> |
x:i:1;O:8:"stdClass":0:{}, s:13:"GeeksforGeeks";;m:a:0:{}
Program 2:
<?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"); ?> |
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
Recommended Posts:
- PHP | SplObjectStorage next() Function
- PHP | SplObjectStorage key() Function
- PHP | SplObjectStorage contains() Function
- PHP | SplObjectStorage offsetUnset() Function
- PHP | SplObjectStorage offsetSet() Function
- PHP | SplObjectStorage offsetExists() Function
- PHP | SplObjectStorage unserialize() Function
- PHP | SplObjectStorage offsetGet() Function
- PHP | SplObjectStorage removeAll() Function
- PHP | SplObjectStorage removeAllExcept() Function
- PHP | SplObjectStorage rewind() Function
- PHP | SplObjectStorage setInfo() Function
- PHP | SplObjectStorage attach() Function
- PHP | SplObjectStorage valid() Function
- PHP | SplObjectStorage addAll() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



