PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/hphp/test/zend/bad/ext/standard/tests/file/mkdir_variation4.php

http://github.com/facebook/hiphop-php
PHP | 121 lines | 71 code | 25 blank | 25 comment | 3 complexity | 9574eb3ddbf8ddf9a0340257e28a08f8 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. /* Prototype : bool mkdir(string pathname [, int mode [, bool recursive [, resource context]]])
  3. * Description: Create a directory
  4. * Source code: ext/standard/file.c
  5. * Alias to functions:
  6. */
  7. echo "*** Testing mkdir() : usage variation ***\n";
  8. // Define error handler
  9. function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
  10. if (error_reporting() != 0) {
  11. // report non-silenced errors
  12. echo "Error: $err_no - $err_msg, $filename($linenum)\n";
  13. }
  14. }
  15. set_error_handler('test_error_handler');
  16. // Initialise function arguments not being substituted (if any)
  17. $pathname = 'mkdirVar4.tmp';
  18. $mode = 0777;
  19. $recursive = false;
  20. //get an unset variable
  21. $unset_var = 10;
  22. unset ($unset_var);
  23. // define some classes
  24. class classWithToString
  25. {
  26. public function __toString() {
  27. return "Class A object";
  28. }
  29. }
  30. class classWithoutToString
  31. {
  32. }
  33. // heredoc string
  34. $heredoc = <<<EOT
  35. hello world
  36. EOT;
  37. // add arrays
  38. $index_array = array (1, 2, 3);
  39. $assoc_array = array ('one' => 1, 'two' => 2);
  40. $fileRes = fopen(__FILE__,'r');
  41. //array of values to iterate over
  42. $inputs = array(
  43. // int data
  44. 'int 0' => 0,
  45. 'int 1' => 1,
  46. 'int 12345' => 12345,
  47. 'int -12345' => -2345,
  48. // float data
  49. 'float 10.5' => 10.5,
  50. 'float -10.5' => -10.5,
  51. 'float 12.3456789000e10' => 12.3456789000e10,
  52. 'float -12.3456789000e10' => -12.3456789000e10,
  53. 'float .5' => .5,
  54. // array data
  55. 'empty array' => array(),
  56. 'int indexed array' => $index_array,
  57. 'associative array' => $assoc_array,
  58. 'nested arrays' => array('foo', $index_array, $assoc_array),
  59. // null data
  60. 'uppercase NULL' => NULL,
  61. 'lowercase null' => null,
  62. // boolean data
  63. 'lowercase true' => true,
  64. 'lowercase false' =>false,
  65. 'uppercase TRUE' =>TRUE,
  66. 'uppercase FALSE' =>FALSE,
  67. // empty data
  68. 'empty string DQ' => "",
  69. 'empty string SQ' => '',
  70. // string data
  71. 'string DQ' => "string",
  72. 'string SQ' => 'string',
  73. 'mixed case string' => "sTrInG",
  74. 'heredoc' => $heredoc,
  75. // object data
  76. 'instance of classWithToString' => new classWithToString(),
  77. 'instance of classWithoutToString' => new classWithoutToString(),
  78. // undefined data
  79. 'undefined var' => @$undefined_var,
  80. // unset data
  81. 'unset var' => @$unset_var,
  82. // non stream context resource
  83. 'file resource' => $fileRes,
  84. );
  85. // loop through each element of the array for context
  86. foreach($inputs as $key =>$value) {
  87. echo "\n--$key--\n";
  88. $h = mkdir($pathname, $mode, $recursive, $value);
  89. if ($h === true) {
  90. echo "Directory created\n";
  91. rmdir($pathname);
  92. }
  93. };
  94. fclose($fileRes);
  95. ?>
  96. ===DONE===