fscanf_variation52.phpt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. --TEST--
  2. Test fscanf() function: usage variations - empty file
  3. --FILE--
  4. <?php
  5. /* Test fscanf() to scan an empty file */
  6. $file_path = __DIR__;
  7. echo "*** Test fscanf(): to read an empty file ***\n";
  8. // various formats
  9. $formats = array( "%d", "%f", "%e", "%u", " %s", "%x", "%o");
  10. $counter = 1;
  11. // various read modes
  12. $modes = array("r", "rb", "rt", "r+", "r+b", "r+t",
  13. "w+", "w+b", "w+t",
  14. "a+", "a+b", "a+t"
  15. );
  16. $counter = 1;
  17. // reading the values from file using different integer formats
  18. foreach($modes as $mode) {
  19. // create an empty file
  20. $filename = "$file_path/fscanf_variation52.tmp";
  21. $file_handle = fopen($filename, "w");
  22. if($file_handle == false)
  23. exit("Error:failed to open file $filename");
  24. //closing the file
  25. fclose($file_handle);
  26. // opening file in $mode mode
  27. $file_handle = fopen($filename, $mode);
  28. if($file_handle == false) {
  29. exit("Error:failed to open file $filename");
  30. }
  31. echo "\n-- iteration $counter --\n";
  32. foreach($formats as $format) {
  33. var_dump( fscanf($file_handle,$format) );
  34. rewind($file_handle);
  35. }
  36. $counter++;
  37. fclose($file_handle);
  38. unlink($filename);
  39. }
  40. echo "\n*** Done ***";
  41. ?>
  42. --CLEAN--
  43. <?php
  44. $file_path = __DIR__;
  45. $filename = "$file_path/fscanf_variation52.tmp";
  46. if(file_exists($filename)) {
  47. unlink($filename);
  48. }
  49. ?>
  50. --EXPECT--
  51. *** Test fscanf(): to read an empty file ***
  52. -- iteration 1 --
  53. bool(false)
  54. bool(false)
  55. bool(false)
  56. bool(false)
  57. bool(false)
  58. bool(false)
  59. bool(false)
  60. -- iteration 2 --
  61. bool(false)
  62. bool(false)
  63. bool(false)
  64. bool(false)
  65. bool(false)
  66. bool(false)
  67. bool(false)
  68. -- iteration 3 --
  69. bool(false)
  70. bool(false)
  71. bool(false)
  72. bool(false)
  73. bool(false)
  74. bool(false)
  75. bool(false)
  76. -- iteration 4 --
  77. bool(false)
  78. bool(false)
  79. bool(false)
  80. bool(false)
  81. bool(false)
  82. bool(false)
  83. bool(false)
  84. -- iteration 5 --
  85. bool(false)
  86. bool(false)
  87. bool(false)
  88. bool(false)
  89. bool(false)
  90. bool(false)
  91. bool(false)
  92. -- iteration 6 --
  93. bool(false)
  94. bool(false)
  95. bool(false)
  96. bool(false)
  97. bool(false)
  98. bool(false)
  99. bool(false)
  100. -- iteration 7 --
  101. bool(false)
  102. bool(false)
  103. bool(false)
  104. bool(false)
  105. bool(false)
  106. bool(false)
  107. bool(false)
  108. -- iteration 8 --
  109. bool(false)
  110. bool(false)
  111. bool(false)
  112. bool(false)
  113. bool(false)
  114. bool(false)
  115. bool(false)
  116. -- iteration 9 --
  117. bool(false)
  118. bool(false)
  119. bool(false)
  120. bool(false)
  121. bool(false)
  122. bool(false)
  123. bool(false)
  124. -- iteration 10 --
  125. bool(false)
  126. bool(false)
  127. bool(false)
  128. bool(false)
  129. bool(false)
  130. bool(false)
  131. bool(false)
  132. -- iteration 11 --
  133. bool(false)
  134. bool(false)
  135. bool(false)
  136. bool(false)
  137. bool(false)
  138. bool(false)
  139. bool(false)
  140. -- iteration 12 --
  141. bool(false)
  142. bool(false)
  143. bool(false)
  144. bool(false)
  145. bool(false)
  146. bool(false)
  147. bool(false)
  148. *** Done ***