ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[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 ```