SplObjectStorage 存储对象列表
最后更新于:2022-04-02 02:26:13
[TOC]
## 实例
```
interface animal {
public function say();
}
class People implements animal {
public function say(){
echo "say People \n";
}
}
class Dog implements animal {
public function say(){
echo "say Dog \n";
}
}
class Cat implements animal{
public function say()
{
echo "say Cat \n";
}
}
$p= new People();
$d= new Dog();
$c= new Cat();
$obj = new SplObjectStorage();
$obj->attach($p);
$obj->attach($d);
$obj->attach($c);
$obj->detach($c);
echo $obj->count(); //2
var_dump($obj->contains($p)); //true 是否包含 $a
var_dump($obj->valid()); //true
//rewind 使 $obj 可反复遍历
$obj->rewind();
while($obj->valid()){
$current = $obj->current();
$current->say();
$obj->next();
}
//say People
//say Dog
```
';