fileobject_002.phpt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. --TEST--
  2. SPL: SplFileObject::fgetc
  3. --FILE--
  4. <?php
  5. function test($name)
  6. {
  7. echo "===$name===\n";
  8. $o = new SplFileObject(__DIR__ . '/' . $name);
  9. var_dump($o->key());
  10. while(($c = $o->fgetc()) !== false)
  11. {
  12. // Kinda ugly but works around new lines mess
  13. if ($c === "\r") {
  14. continue;
  15. }
  16. var_dump($o->key(), $c, $o->eof());
  17. }
  18. echo "===EOF?===\n";
  19. var_dump($o->eof());
  20. var_dump($o->key());
  21. var_dump($o->eof());
  22. }
  23. test('fileobject_001a.txt');
  24. test('fileobject_001b.txt');
  25. ?>
  26. --EXPECT--
  27. ===fileobject_001a.txt===
  28. int(0)
  29. int(0)
  30. string(1) "0"
  31. bool(false)
  32. int(1)
  33. string(1) "
  34. "
  35. bool(false)
  36. int(1)
  37. string(1) "1"
  38. bool(false)
  39. int(2)
  40. string(1) "
  41. "
  42. bool(false)
  43. int(2)
  44. string(1) "2"
  45. bool(false)
  46. int(3)
  47. string(1) "
  48. "
  49. bool(false)
  50. int(3)
  51. string(1) "3"
  52. bool(false)
  53. int(4)
  54. string(1) "
  55. "
  56. bool(false)
  57. int(4)
  58. string(1) "4"
  59. bool(false)
  60. int(5)
  61. string(1) "
  62. "
  63. bool(false)
  64. int(5)
  65. string(1) "5"
  66. bool(false)
  67. int(6)
  68. string(1) "
  69. "
  70. bool(false)
  71. ===EOF?===
  72. bool(true)
  73. int(6)
  74. bool(true)
  75. ===fileobject_001b.txt===
  76. int(0)
  77. int(0)
  78. string(1) "0"
  79. bool(false)
  80. int(1)
  81. string(1) "
  82. "
  83. bool(false)
  84. int(1)
  85. string(1) "1"
  86. bool(false)
  87. int(2)
  88. string(1) "
  89. "
  90. bool(false)
  91. int(2)
  92. string(1) "2"
  93. bool(false)
  94. int(3)
  95. string(1) "
  96. "
  97. bool(false)
  98. int(3)
  99. string(1) "3"
  100. bool(false)
  101. int(4)
  102. string(1) "
  103. "
  104. bool(false)
  105. int(4)
  106. string(1) "4"
  107. bool(false)
  108. int(5)
  109. string(1) "
  110. "
  111. bool(false)
  112. int(5)
  113. string(1) "5"
  114. bool(false)
  115. ===EOF?===
  116. bool(true)
  117. int(5)
  118. bool(true)