<?php
class Test{
private $sp;
public function __construct(){
$this->sp = new SplObjectStorage();
}
public function addToSpl($object){
$this->sp->attach($object);
}
public function getSp()
{
return $this->sp;
}
}
$t = new Test();
$t->addToSpl(new StdClass());
$t->addToSpl(new StdClass());
$t->addToSpl(new StdClass());
$sp = $t->getSp();
foreach ($sp as $v){
echo "First \n";
$s = $t->getSp();
foreach ($s as $a){
echo "Second \n";
}
}
PD9waHAKCmNsYXNzIFRlc3R7CiAgICBwcml2YXRlICRzcDsKCiAgICBwdWJsaWMgZnVuY3Rpb24gX19jb25zdHJ1Y3QoKXsKICAgICAgICAkdGhpcy0+c3AgPSBuZXcgU3BsT2JqZWN0U3RvcmFnZSgpOwogICAgfQoKICAgIHB1YmxpYyBmdW5jdGlvbiBhZGRUb1NwbCgkb2JqZWN0KXsKICAgICAgICAkdGhpcy0+c3AtPmF0dGFjaCgkb2JqZWN0KTsKICAgIH0KCiAgICBwdWJsaWMgZnVuY3Rpb24gZ2V0U3AoKQogICAgewogICAgICAgIHJldHVybiAkdGhpcy0+c3A7CiAgICB9Cn0KCiR0ID0gbmV3IFRlc3QoKTsKCiR0LT5hZGRUb1NwbChuZXcgU3RkQ2xhc3MoKSk7CiR0LT5hZGRUb1NwbChuZXcgU3RkQ2xhc3MoKSk7CiR0LT5hZGRUb1NwbChuZXcgU3RkQ2xhc3MoKSk7Cgokc3AgPSAkdC0+Z2V0U3AoKTsKCmZvcmVhY2ggKCRzcCBhcyAkdil7CiAgICBlY2hvICJGaXJzdCBcbiI7CiAgICAkcyA9ICR0LT5nZXRTcCgpOwogICAgZm9yZWFjaCAoJHMgYXMgJGEpewogICAgICAgIGVjaG8gIlNlY29uZCBcbiI7CiAgICB9Cn0=