SplObjectStorage::detach()函数是PHP中的内置函数,用于从存储中删除对象。
用法:
void SplObjectStorage::detach($obj)
参数:该函数接受单个参数$obj,该参数指定要从存储中删除的对象。
返回值:该函数不返回任何值。
以下程序说明了PHP中的SplObjectStorage::detach()函数:
程序1:
<?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));
?>
输出:
int(1) int(0)
程序2:
<?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));
?>
输出:
int(3) int(2) int(1)
参考: https://www.php.net/manual/en/splobjectstorage.detach.php
相关用法
- PHP SplObjectStorage next()用法及代码示例
- PHP SplObjectStorage key()用法及代码示例
- PHP SplObjectStorage contains()用法及代码示例
- PHP SplObjectStorage attach()用法及代码示例
- PHP SplObjectStorage addAll()用法及代码示例
- PHP SplObjectStorage valid()用法及代码示例
- PHP SplObjectStorage offsetUnset()用法及代码示例
- PHP SplObjectStorage current()用法及代码示例
- PHP SplObjectStorage getinfo()用法及代码示例
- PHP SplObjectStorage offsetSet()用法及代码示例
- PHP SplObjectStorage offsetExists()用法及代码示例
- PHP SplObjectStorage offsetGet()用法及代码示例
- PHP SplObjectStorage count()用法及代码示例
- PHP SplObjectStorage unserialize()用法及代码示例
- PHP SplObjectStorage setInfo()用法及代码示例
注:本文由纯净天空筛选整理自R_Raj大神的英文原创作品 PHP | SplObjectStorage detach() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。