chmod_variation4.phpt 4.0 KB

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