PHP | SplObjectStorage getinfo() Function
The SplObjectStorage::getinfo() function is an inbuilt function in PHP which is used to get the data associated with the object by the current iterator position.
Syntax:
mixed SplObjectStorage::getinfo()
Parameters: This function does not accept any parameter.
Return Value: This function returns the object associated by the current iterator position.
Below programs illustrate the SplObjectStorage::getinfo() function in PHP:
Program 1:
<?php // Create New Empty Storage Class $str = new SplObjectStorage(); $obj1 = new StdClass; $str->attach($obj1, "GeksforGeeks"); $str->rewind(); $object = $str->current(); // Get info into $data $data = $str->getInfo(); // Print Result var_dump($object); var_dump($data); ?> |
object(stdClass)#2 (0) {
}
string(12) "GeksforGeeks"
Program 2:
<?php // Create an Empty SplObjectStorage $str = new SplObjectStorage(); $obj1 = new StdClass; $obj2 = new StdClass; $obj3 = new StdClass; $obj4 = new StdClass; $str->attach($obj1, "GeksforGeeks"); $str->attach($obj2, "GFG"); $str->attach($obj3); $str->attach($obj4, "DSA"); $str->rewind(); // Iterate and print data on each index while($str->valid()) { $index = $str->key(); $object = $str->current(); $data = $str->getInfo(); var_dump($object); var_dump($data); $str->next(); } ?> |
object(stdClass)#2 (0) {
}
string(12) "GeksforGeeks"
object(stdClass)#3 (0) {
}
string(3) "GFG"
object(stdClass)#4 (0) {
}
NULL
object(stdClass)#5 (0) {
}
string(3) "DSA"
Reference: https://www.php.net/manual/en/splobjectstorage.getinfo.php
Recommended Posts:
- PHP | SplObjectStorage key() Function
- PHP | SplObjectStorage contains() Function
- PHP | SplObjectStorage next() Function
- PHP | SplObjectStorage setInfo() Function
- PHP | SplObjectStorage serialize() Function
- PHP | SplObjectStorage detach() Function
- PHP | SplObjectStorage unserialize() Function
- PHP | SplObjectStorage offsetUnset() Function
- PHP | SplObjectStorage offsetSet() Function
- PHP | SplObjectStorage offsetExists() Function
- PHP | SplObjectStorage offsetGet() Function
- PHP | SplObjectStorage removeAll() Function
- PHP | SplObjectStorage removeAllExcept() Function
- PHP | SplObjectStorage current() Function
- PHP | SplObjectStorage rewind() 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.



