iterator_046.phpt 827 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. --TEST--
  2. SPL: CachingIterator and __toString using bypassed string keys
  3. --FILE--
  4. <?php
  5. class MyFoo
  6. {
  7. function __toString()
  8. {
  9. return 'foo';
  10. }
  11. }
  12. class MyCachingIterator extends CachingIterator
  13. {
  14. function __construct(Iterator $it, $flags = 0)
  15. {
  16. parent::__construct($it, $flags);
  17. }
  18. function fill()
  19. {
  20. echo __METHOD__ . "()\n";
  21. foreach($this as $v) ;
  22. }
  23. function show()
  24. {
  25. echo __METHOD__ . "()\n";
  26. foreach($this as $v)
  27. {
  28. var_dump((string)$this);
  29. }
  30. }
  31. }
  32. $it = new MyCachingIterator(new ArrayIterator(array(0, 'foo'=>1, 'bar'=>2)), CachingIterator::TOSTRING_USE_KEY);
  33. $it->fill();
  34. $it->show();
  35. ?>
  36. --EXPECT--
  37. MyCachingIterator::fill()
  38. MyCachingIterator::show()
  39. string(1) "0"
  40. string(3) "foo"
  41. string(3) "bar"