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 current iterator entry of the storage.
Return Value: This function does not return any value.
Below programs illustrate the SplObjectStorage::setInfo() function in PHP:
Program 1:
<?php $str = new SplObjectStorage(); $obj1 = new StdClass; $str->attach($obj1, "GeeksforGeeks"); $str->rewind(); // Set new info for $obj1 in storage $str $str->setInfo("new_GeeksforGeeks"); // Print Result var_dump($str[$obj1]); ?> |
string(17) "new_GeeksforGeeks"
Program 2:
<?php $obj1 = new StdClass; $obj2 = new StdClass; $obj3 = new StdClass; $gfg = new SplObjectStorage(); $gfg[$obj1] = "GFG"; $gfg[$obj2] = "GeeksClasses"; $gfg[$obj3] = "SUDO"; // Using rewind function $gfg->rewind(); while($gfg->valid()) { $gfg->setInfo("Modified_GFG_DATA"); var_dump($gfg->getInfo()); // Moving to next element $gfg->next(); } ?> |
string(17) "Modified_GFG_DATA" string(17) "Modified_GFG_DATA" string(17) "Modified_GFG_DATA"
Reference: https://www.php.net/manual/en/splobjectstorage.setinfo.php
Recommended Posts:
- PHP | SplObjectStorage contains() Function
- PHP | SplObjectStorage next() Function
- PHP | SplObjectStorage key() Function
- PHP | SplObjectStorage current() Function
- PHP | SplObjectStorage offsetSet() Function
- PHP | SplObjectStorage removeAllExcept() Function
- PHP | SplObjectStorage rewind() Function
- PHP | SplObjectStorage serialize() Function
- PHP | SplObjectStorage unserialize() Function
- PHP | SplObjectStorage removeAll() Function
- PHP | SplObjectStorage offsetExists() Function
- PHP | SplObjectStorage offsetGet() Function
- PHP | SplObjectStorage offsetUnset() Function
- PHP | SplObjectStorage detach() 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.



