fork download
  1. <?php
  2.  
  3. class Test{
  4. private $sp;
  5.  
  6. public function __construct(){
  7. $this->sp = new SplObjectStorage();
  8. }
  9.  
  10. public function addToSpl($object){
  11. $this->sp->attach($object);
  12. }
  13.  
  14. public function getSp()
  15. {
  16. return $this->sp;
  17. }
  18. }
  19.  
  20. $t = new Test();
  21.  
  22. $t->addToSpl(new StdClass());
  23. $t->addToSpl(new StdClass());
  24. $t->addToSpl(new StdClass());
  25.  
  26. $sp = $t->getSp();
  27.  
  28. foreach ($sp as $v){
  29. echo "First \n";
  30. $s = $t->getSp();
  31. foreach ($s as $a){
  32. echo "Second \n";
  33. }
  34. }
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
First 
Second 
Second 
Second