file_variation2.phpt 4.9 KB

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