PHP SplObjectStorage count() Function Last Updated : 23 Jun, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 programs illustrate the SplObjectStorage::count() function in PHP: Program 1: php <?php // Declare Empty SplObjectStorage $gfg = new SplObjectStorage(); $gfg1 = new StdClass; $gfg2 = new StdClass; $gfg3 = new StdClass; // Add object to SplObjectStorage class $gfg->attach($gfg1); $gfg->attach($gfg2); $gfg->attach($gfg3); // Use count() function to count object var_dump($gfg->count()); ?> Output: int(3) Program 2: php <?php // Declare Empty SplObjectStorage $gfg = new SplObjectStorage(); $gfg1 = new StdClass; $gfg2 = new StdClass; $gfg3 = new StdClass; // Add object to SplObjectStorage class $gfg->attach($gfg1); $gfg->attach($gfg2); $gfg->attach($gfg3); // Use count in different way // Passing object as parameter var_dump(count($gfg)); ?> Output: int(3) Reference: https://www.php.net/manual/en/splobjectstorage.count.php Comment More infoAdvertise with us Next Article PHP SplObjectStorage count() Function R R_Raj Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP SplObjectStorage current() Function The SplObjectStorage::current() function is an inbuilt function in PHP which is used get the current entry of storage. Syntax: object SplObjectStorage::current() Parameters: This function does not accept any parameter. Return Value: This function returns the object of the current storage. Below prog 1 min read PHP SplObjectStorage contains() Function The SplObjectStorage::contains() function is an inbuilt function in PHP which is used to check the storage object contains a specified object or not. Syntax: bool SplObjectStorage::contains( $value ) Parameters: This function accepts a single parameter $value which specifies the storage object which 1 min read PHP SplObjectStorage detach() Function The SplObjectStorage::detach() function is an inbuilt function in PHP which is used to remove objects from the storage. Syntax: void SplObjectStorage::detach($obj) Parameters: This function accepts a single parameter $obj which specifies the object to be remove from the storage. Return Value: This f 1 min read PHP SplObjectStorage attach() Function The SplObjectStorage::attach() function is an inbuilt function in PHP which is used to add objects into the SplObjectStorage. Syntax: void SplObjectStorage::attach($obj, $val) Parameters: This function accepts two parameters as mention above and described below. $obj: This is required parameter whic 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