Skip to content
Related Articles

Related Articles

PHP | SplObjectStorage setInfo() Function

Improve Article
Save Article
Like Article
  • Last Updated : 23 Aug, 2019

The SplObjectStorage::setInfo() function is an inbuilt function in PHP which is used to set the data associated with the current iterator entry.


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:

$str = new SplObjectStorage();
$obj1 = new StdClass;
$str->attach($obj1, "GeeksforGeeks");
// Set new info for $obj1 in storage $str
// Print Result
string(17) "new_GeeksforGeeks"

Program 2:

$obj1 = new StdClass;
$obj2 = new StdClass;
$obj3 = new StdClass;
$gfg = new SplObjectStorage();
$gfg[$obj1] = "GFG";
$gfg[$obj2] = "GeeksClasses";
$gfg[$obj3] = "SUDO";
// Using rewind function
while($gfg->valid()) {
    // Moving to next element
string(17) "Modified_GFG_DATA"
string(17) "Modified_GFG_DATA"
string(17) "Modified_GFG_DATA"


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!