Open In App
Related Articles

PHP SplObjectStorage setInfo() Function

Improve Article
Save Article
Like Article

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"


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 23 Jun, 2023
Like Article
Save Article
Similar Reads
Complete Tutorials