phar_buildfromiterator9.phpt 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. --TEST--
  2. Phar::buildFromIterator() iterator, 1 file resource passed in
  3. --EXTENSIONS--
  4. phar
  5. --INI--
  6. phar.require_hash=0
  7. phar.readonly=0
  8. --FILE--
  9. <?php
  10. class myIterator implements Iterator
  11. {
  12. var $a;
  13. function __construct(array $a)
  14. {
  15. $this->a = $a;
  16. }
  17. function next(): void {
  18. echo "next\n";
  19. next($this->a);
  20. }
  21. function current(): mixed {
  22. echo "current\n";
  23. return current($this->a);
  24. }
  25. function key(): mixed {
  26. echo "key\n";
  27. return key($this->a);
  28. }
  29. function valid(): bool {
  30. echo "valid\n";
  31. return (bool) current($this->a);
  32. }
  33. function rewind(): void {
  34. echo "rewind\n";
  35. reset($this->a);
  36. }
  37. }
  38. try {
  39. chdir(__DIR__);
  40. $phar = new Phar(__DIR__ . '/buildfromiterator9.phar');
  41. var_dump($phar->buildFromIterator(new myIterator(array('a' => $a = fopen(basename(__FILE__, 'php') . 'phpt', 'r')))));
  42. fclose($a);
  43. } catch (Exception $e) {
  44. var_dump(get_class($e));
  45. echo $e->getMessage() . "\n";
  46. }
  47. ?>
  48. --CLEAN--
  49. <?php
  50. unlink(__DIR__ . '/buildfromiterator9.phar');
  51. __HALT_COMPILER();
  52. ?>
  53. --EXPECTF--
  54. rewind
  55. valid
  56. current
  57. key
  58. next
  59. valid
  60. array(1) {
  61. ["a"]=>
  62. string(%d) "[stream]"
  63. }