fopen_variation3.phpt 4.0 KB

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