PHP SplObjectStorage valid() Function Last Updated : 23 Jun, 2023 Comments Improve Suggest changes Like Article Like Report The SplObjectStorage::valid() function is an inbuilt function in PHP which is used to check the current storage entry is valid or not. Syntax: bool SplObjectStorage::valid() Parameters: This function does not accept any parameter. Return Value: This function returns true if the iterator entry is valid, false otherwise. Below programs illustrate the SplObjectStorage::valid() function in PHP: Program 1: php <?php // Create an empty SplObjectStorage $str = new SplObjectStorage(); $obj = new StdClass; $obj2 = new StdClass; $obj3 = new StdClass; // Use attach() function to // add object $str->attach($obj, "GFG"); // Use rewind() function to rewind the // iterator to the first storage element $str->rewind(); // Use valid() function to check current // iterator is valid entry or not print($str->valid()); ?> Output: 1 Program 2: php <?php // Create an empty SplObjectStorage $gfg = new SplObjectStorage(); $obj1 = new StdClass; $obj2 = new StdClass; $obj3 = new StdClass; $gfg[$obj1] = "GFG"; $gfg[$obj2] = "GeeksClasses"; $gfg[$obj3] = "SUDO"; // Use rewind function $gfg->rewind(); while($gfg->valid()) { var_dump($gfg->getInfo()); // Moving to next element $gfg->next(); } ?> Output: string(3) "GFG" string(12) "GeeksClasses" string(4) "SUDO" Reference: https://www.php.net/manual/en/splobjectstorage.valid.php Comment More infoAdvertise with us Next Article PHP SplObjectStorage valid() Function R R_Raj Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP SplObjectStorage unserialize() Function The SplObjectStorage::unserialize() function is an inbuilt function in PHP which is used to unserialize the storage from its serialize string representation. Syntax: void SplObjectStorage::unserialize( $serilize ) Parameters: This function accepts a single parameter $serialize which specifies the st 1 min read PHP SplObjectStorage key() Function The SplObjectStorage::key() function is an inbuilt function in PHP which is used to get the index of the currently pointing iterator. Syntax: int SplObjectStorage::key() Parameters: This function does not accept any parameter. Return Value: This function returns the index at which the iterator curre 1 min read PHP SplObjectStorage next() Function The SplObjectStorage::next() function is an inbuilt function in PHP which is used to move to next entry of storage. Syntax: void SplObjectStorage::next() Parameters: This function does not accept any parameter. Return Value: This function does not return any value. Below programs illustrate the SplO 1 min read PHP SplObjectStorage count() Function The SplObjectStorage::count() function is an inbuilt function in PHP which is used to count the number of objects in storage. Syntax: int SplObjectStorage::count() Parameters: This function does not contains any parameter. Return Value: This function returns number of objects in storage. Below progr 1 min read PHP SplObjectStorage addAll() Function The SplObjectStorage::addAll() function is an inbuilt function in PHP which is used to add elements from another storage. Syntax: void SplObjectStorage::addAll( $value ) Parameters: This function accepts a single parameter $value which holds an storage which need to import. Return Value: It does not 1 min read Like