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 , "neveropen" ); $str -> rewind (); // Set new info for $obj1 in storage $str $str ->setInfo( "new_neveropen" ); // Print Result var_dump( $str [ $obj1 ]); ?> |
string(17) "new_neveropen"
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