PHP | SplObjectStorage offsetGet() Function
The SplObjectStorage::offsetGet() function is an inbuilt function in PHP which is used to get the data associated with the object.
Syntax:
object SplObjectStorage::offsetGet($obj)
Parameters: This function accepts a single parameter $obj which specifies the object to be fetch.
Return Value: This function returns the data previously associated with the object in the storage.
Below programs illustrate the SplObjectStorage::offsetGet() function in PHP:
Program 1:
<?php // Create an empty SplObjectStorage $str = new SplObjectStorage; $obj = new StdClass; // Attch $obj to $str $str->attach($obj, "GeeksforGeeks"); // Print Result var_dump($str->offsetGet($obj)); ?> |
string(13) "GeeksforGeeks"
Program 2:
<?php // Create an Empty SplObjectStorage $str = new SplObjectStorage(); $obj1 = new StdClass; $obj2 = new StdClass; $obj3 = new StdClass; $obj4 = new StdClass; // Attach objects $str->attach($obj1, "GeksforGeeks"); $str->attach($obj2, "GFG"); $str->attach($obj3); $str->attach($obj4, "Hello GFG"); // Print result var_dump($str->offsetGet($obj1)); var_dump($str->offsetGet($obj2)); var_dump($str->offsetGet($obj4)); var_dump($str->offsetGet($obj3)); ?> |
string(12) "GeksforGeeks" string(3) "GFG" string(9) "Hello GFG" NULL
Reference: https://www.php.net/manual/en/splobjectstorage.offsetget.php
Recommended Posts:
- PHP | SplFixedArray offsetGet() Function
- ArrayObject offsetGet() Function in PHP
- PHP | SplDoublyLinkedList offsetGet() Function
- PHP | SplObjectStorage key() Function
- PHP | SplObjectStorage next() Function
- PHP | SplObjectStorage contains() Function
- PHP | SplObjectStorage valid() Function
- PHP | SplObjectStorage count() Function
- PHP | SplObjectStorage addAll() Function
- PHP | SplObjectStorage offsetExists() Function
- PHP | SplObjectStorage offsetUnset() Function
- PHP | SplObjectStorage serialize() Function
- PHP | SplObjectStorage rewind() Function
- PHP | SplObjectStorage removeAll() Function
- PHP | SplObjectStorage current() 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.




