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 ();
$str ->setInfo( "new_GeeksforGeeks" );
var_dump( $str [ $obj1 ]);
?>
|
Output:
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" ;
$gfg -> rewind ();
while ( $gfg ->valid()) {
$gfg ->setInfo( "Modified_GFG_DATA" );
var_dump( $gfg ->getInfo());
$gfg ->next();
}
?>
|
Output:
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