PHP SplObjectStorage detach() Function Last Updated : 23 Jun, 2023 Comments Improve Suggest changes Like Article Like Report 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 function does not return any value. Below programs illustrate the SplObjectStorage::detach() function in PHP: Program 1: php <?php // Creating class $obj = new StdClass; // Create an empty storage class $str = new SplObjectStorage(); // Add some object $str->attach($obj, "GeeksforGeeks"); // Print result before detaching var_dump(count($str)); // Detaching object $str->detach($obj); // Print result after detach var_dump(count($str)); ?> Output: int(1) int(0) Program 2: php <?php // Creating class $obj1 = new StdClass; $obj2 = new StdClass; $obj3 = new StdClass; // Create an empty storage class $str = new SplObjectStorage(); // Add some object $str->attach($obj1, "GeeksforGeeks"); $str->attach($obj2); $str->attach($obj3, "GFG"); // Print result before detaching var_dump(count($str)); // Detaching object $str->detach($obj1); // Print result after detach first object var_dump(count($str)); // Detaching object $str->detach($obj3); // Print result after detach second object var_dump(count($str)); ?> Output: int(3) int(2) int(1) Reference: https://www.php.net/manual/en/splobjectstorage.detach.php Comment More infoAdvertise with us Next Article PHP SplObjectStorage detach() Function R R_Raj Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads 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 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 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 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 Like