mkdir_variation3.phpt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. --TEST--
  2. Test mkdir() function : usage variation: different types for recursive
  3. --CREDITS--
  4. Dave Kelsey <d_kelsey@uk.ibm.com>
  5. --FILE--
  6. <?php
  7. /* Prototype : bool mkdir(string pathname [, int mode [, bool recursive [, resource context]]])
  8. * Description: Create a directory
  9. * Source code: ext/standard/file.c
  10. * Alias to functions:
  11. */
  12. echo "*** Testing mkdir() : 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. $pathname = 'mkdirVar3.tmp';
  23. $mode = 0777;
  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 recursive
  87. foreach($inputs as $key =>$value) {
  88. echo "\n--$key--\n";
  89. $h = mkdir($pathname, $mode, $value);
  90. if ($h === true) {
  91. echo "Directory created\n";
  92. rmdir($pathname);
  93. }
  94. };
  95. ?>
  96. ===DONE===
  97. --EXPECTF--
  98. *** Testing mkdir() : usage variation ***
  99. --int 0--
  100. Directory created
  101. --int 1--
  102. Directory created
  103. --int 12345--
  104. Directory created
  105. --int -12345--
  106. Directory created
  107. --float 10.5--
  108. Directory created
  109. --float -10.5--
  110. Directory created
  111. --float 12.3456789000e10--
  112. Directory created
  113. --float -12.3456789000e10--
  114. Directory created
  115. --float .5--
  116. Directory created
  117. --empty array--
  118. Error: 2 - mkdir() expects parameter 3 to be boolean, array given, %s(%d)
  119. --int indexed array--
  120. Error: 2 - mkdir() expects parameter 3 to be boolean, array given, %s(%d)
  121. --associative array--
  122. Error: 2 - mkdir() expects parameter 3 to be boolean, array given, %s(%d)
  123. --nested arrays--
  124. Error: 2 - mkdir() expects parameter 3 to be boolean, array given, %s(%d)
  125. --uppercase NULL--
  126. Directory created
  127. --lowercase null--
  128. Directory created
  129. --lowercase true--
  130. Directory created
  131. --lowercase false--
  132. Directory created
  133. --uppercase TRUE--
  134. Directory created
  135. --uppercase FALSE--
  136. Directory created
  137. --empty string DQ--
  138. Directory created
  139. --empty string SQ--
  140. Directory created
  141. --string DQ--
  142. Directory created
  143. --string SQ--
  144. Directory created
  145. --mixed case string--
  146. Directory created
  147. --heredoc--
  148. Directory created
  149. --instance of classWithToString--
  150. Error: 2 - mkdir() expects parameter 3 to be boolean, object given, %s(%d)
  151. --instance of classWithoutToString--
  152. Error: 2 - mkdir() expects parameter 3 to be boolean, object given, %s(%d)
  153. --undefined var--
  154. Directory created
  155. --unset var--
  156. Directory created
  157. ===DONE===