readfile_variation5.phpt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. --TEST--
  2. Test readfile() function : usage variation
  3. --CREDITS--
  4. Dave Kelsey <d_kelsey@uk.ibm.com>
  5. --FILE--
  6. <?php
  7. /* Prototype : int readfile(string filename [, bool use_include_path[, resource context]])
  8. * Description: Output a file or a URL
  9. * Source code: ext/standard/file.c
  10. * Alias to functions:
  11. */
  12. echo "*** Testing readfile() : usage variation ***\n";
  13. // Define error handler
  14. function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
  15. if (error_reporting() != 0) {
  16. // report non-silenced errors
  17. echo "Error: $err_no - $err_msg, $filename($linenum)\n";
  18. }
  19. }
  20. set_error_handler('test_error_handler');
  21. // Initialise function arguments not being substituted (if any)
  22. $filename = 'readFileVar5.tmp';
  23. $use_include_path = false;
  24. $h = fopen($filename,'wb');
  25. fwrite($h, "testing readfile");
  26. fclose($h);
  27. //get an unset variable
  28. $unset_var = 10;
  29. unset ($unset_var);
  30. // define some classes
  31. class classWithToString
  32. {
  33. public function __toString() {
  34. return "Class A object";
  35. }
  36. }
  37. class classWithoutToString
  38. {
  39. }
  40. // heredoc string
  41. $heredoc = <<<EOT
  42. hello world
  43. EOT;
  44. // add arrays
  45. $index_array = array (1, 2, 3);
  46. $assoc_array = array ('one' => 1, 'two' => 2);
  47. //array of values to iterate over
  48. $inputs = array(
  49. // int data
  50. 'int 0' => 0,
  51. 'int 1' => 1,
  52. 'int 12345' => 12345,
  53. 'int -12345' => -2345,
  54. // float data
  55. 'float 10.5' => 10.5,
  56. 'float -10.5' => -10.5,
  57. 'float 12.3456789000e10' => 12.3456789000e10,
  58. 'float -12.3456789000e10' => -12.3456789000e10,
  59. 'float .5' => .5,
  60. // array data
  61. 'empty array' => array(),
  62. 'int indexed array' => $index_array,
  63. 'associative array' => $assoc_array,
  64. 'nested arrays' => array('foo', $index_array, $assoc_array),
  65. // null data
  66. 'uppercase NULL' => NULL,
  67. 'lowercase null' => null,
  68. // boolean data
  69. 'lowercase true' => true,
  70. 'lowercase false' =>false,
  71. 'uppercase TRUE' =>TRUE,
  72. 'uppercase FALSE' =>FALSE,
  73. // empty data
  74. 'empty string DQ' => "",
  75. 'empty string SQ' => '',
  76. // string data
  77. 'string DQ' => "string",
  78. 'string SQ' => 'string',
  79. 'mixed case string' => "sTrInG",
  80. 'heredoc' => $heredoc,
  81. // object data
  82. 'instance of classWithToString' => new classWithToString(),
  83. 'instance of classWithoutToString' => new classWithoutToString(),
  84. // undefined data
  85. 'undefined var' => @$undefined_var,
  86. // unset data
  87. 'unset var' => @$unset_var,
  88. );
  89. // loop through each element of the array for use_include_path
  90. foreach($inputs as $key =>$value) {
  91. echo "\n--$key--\n";
  92. $res = readfile($filename, $value);
  93. if ($res == false) {
  94. echo "File not read\n";
  95. }
  96. else {
  97. echo "\n";
  98. }
  99. };
  100. unlink($filename);
  101. ?>
  102. ===DONE===
  103. --EXPECTF--
  104. *** Testing readfile() : usage variation ***
  105. --int 0--
  106. testing readfile
  107. --int 1--
  108. testing readfile
  109. --int 12345--
  110. testing readfile
  111. --int -12345--
  112. testing readfile
  113. --float 10.5--
  114. testing readfile
  115. --float -10.5--
  116. testing readfile
  117. --float 12.3456789000e10--
  118. testing readfile
  119. --float -12.3456789000e10--
  120. testing readfile
  121. --float .5--
  122. testing readfile
  123. --empty array--
  124. Error: 2 - readfile() expects parameter 2 to be boolean, array given, %s(%d)
  125. File not read
  126. --int indexed array--
  127. Error: 2 - readfile() expects parameter 2 to be boolean, array given, %s(%d)
  128. File not read
  129. --associative array--
  130. Error: 2 - readfile() expects parameter 2 to be boolean, array given, %s(%d)
  131. File not read
  132. --nested arrays--
  133. Error: 2 - readfile() expects parameter 2 to be boolean, array given, %s(%d)
  134. File not read
  135. --uppercase NULL--
  136. testing readfile
  137. --lowercase null--
  138. testing readfile
  139. --lowercase true--
  140. testing readfile
  141. --lowercase false--
  142. testing readfile
  143. --uppercase TRUE--
  144. testing readfile
  145. --uppercase FALSE--
  146. testing readfile
  147. --empty string DQ--
  148. testing readfile
  149. --empty string SQ--
  150. testing readfile
  151. --string DQ--
  152. testing readfile
  153. --string SQ--
  154. testing readfile
  155. --mixed case string--
  156. testing readfile
  157. --heredoc--
  158. testing readfile
  159. --instance of classWithToString--
  160. Error: 2 - readfile() expects parameter 2 to be boolean, object given, %s(%d)
  161. File not read
  162. --instance of classWithoutToString--
  163. Error: 2 - readfile() expects parameter 2 to be boolean, object given, %s(%d)
  164. File not read
  165. --undefined var--
  166. testing readfile
  167. --unset var--
  168. testing readfile
  169. ===DONE===