chmod_variation4.phpt 4.1 KB

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