SplObjectStorage::unserialize()函数是PHP中的内置函数,用于从其序列化字符串表示形式反序列化存储。
用法:
void SplObjectStorage::unserialize( $serilize )
参数:该函数接受单个参数$serialize,该参数指定存储的字符串序列化。
返回值:该函数不返回任何值。
以下程序说明了PHP中的SplObjectStorage::unserialize()函数:
程序1:
<?php
$obj1 = new StdClass;
// Create an empty SplObjectStorage
$gfg1 = new SplObjectStorage();
$gfg1[$obj1] = "Geeks";
// Use unserialize() function
$gfg1->unserialize($gfg1->serialize());
print_r($gfg1);
?>
输出:
SplObjectStorage Object ( [storage:SplObjectStorage:private] => Array ( [00000000494fcd4d000000001f544823] => Array ( [obj] => stdClass Object ( ) [inf] => Geeks ) [00000000494fcd4f000000001f544823] => Array ( [obj] => stdClass Object ( ) [inf] => Geeks ) ) )
程序2:
<?php
$obj1 = new StdClass;
$obj2 = new StdClass;
// Create an empty SplObjectStorage
$gfg1 = new SplObjectStorage();
$gfg1[$obj1] = "Geeks";
// Create an empty SplObjectStorage
$gfg2 = new SplObjectStorage();
$gfg2[$obj1] = "GFG";
$gfg2[$obj2] = "GeeksClasses";
// Use unserialize() function
$gfg1->unserialize($gfg2->serialize());
var_dump(count($gfg1));
// Use unserialize() function
$gfg2->unserialize($gfg1->serialize());
var_dump(count($gfg2));
?>
输出:
int(3) int(5)
参考: https://www.php.net/manual/en/splobjectstorage.unserialize.php
相关用法
- PHP ArrayObject unserialize()用法及代码示例
- PHP ArrayIterator unserialize()用法及代码示例
- PHP SplDoublyLinkedList unserialize()用法及代码示例
- PHP SplObjectStorage key()用法及代码示例
- PHP SplObjectStorage next()用法及代码示例
- PHP SplObjectStorage contains()用法及代码示例
- PHP SplObjectStorage removeAll()用法及代码示例
- PHP SplObjectStorage rewind()用法及代码示例
- PHP SplObjectStorage offsetUnset()用法及代码示例
- PHP SplObjectStorage setInfo()用法及代码示例
- PHP SplObjectStorage serialize()用法及代码示例
- PHP SplObjectStorage count()用法及代码示例
- PHP SplObjectStorage detach()用法及代码示例
- PHP SplObjectStorage getinfo()用法及代码示例
注:本文由纯净天空筛选整理自R_Raj大神的英文原创作品 PHP | SplObjectStorage unserialize() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。