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 // 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()); ?> |
int(3)
Program 2:
<?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)); ?> |
int(3)
Reference: https://www.php.net/manual/en/splobjectstorage.count.php
Recommended Posts:
- PHP | SplObjectStorage contains() Function
- PHP | SplObjectStorage addAll() Function
- PHP | SplObjectStorage valid() Function
- PHP | SplObjectStorage attach() Function
- PHP | SplObjectStorage current() Function
- PHP | SplObjectStorage next() Function
- PHP | SplObjectStorage detach() Function
- PHP | SplObjectStorage getinfo() Function
- PHP | SplObjectStorage key() Function
- PHP | SplObjectStorage offsetSet() Function
- PHP | SplObjectStorage offsetExists() Function
- PHP | SplObjectStorage offsetGet() Function
- PHP | SplObjectStorage offsetUnset() Function
- PHP | SplObjectStorage removeAll() Function
- PHP | SplObjectStorage removeAllExcept() Function
- PHP | SplObjectStorage rewind() Function
- PHP | SplObjectStorage serialize() Function
- PHP | SplObjectStorage setInfo() Function
- PHP | SplObjectStorage unserialize() Function
- PHP | count() 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.

