class_uses_variation2.phpt 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. --TEST--
  2. SPL: Test class_uses() function : variation
  3. --FILE--
  4. <?php
  5. /* Prototype : array class_uses(mixed what [, bool autoload ])
  6. * Description: Return all traits used by a class
  7. * Source code: ext/spl/php_spl.c
  8. * Alias to functions:
  9. */
  10. echo "*** Testing class_uses() : variation ***\n";
  11. trait foo {}
  12. class fooUser { use foo; }
  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. $class = 'fooUser';
  23. //resource
  24. $res = fopen(__FILE__,'r');
  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. // int data
  48. 'int 0' => 0,
  49. 'int 1' => 1,
  50. 'int 12345' => 12345,
  51. 'int -12345' => -2345,
  52. // float data
  53. 'float 10.5' => 10.5,
  54. 'float -10.5' => -10.5,
  55. 'float 12.3456789000e10' => 12.3456789000e10,
  56. 'float -12.3456789000e10' => -12.3456789000e10,
  57. 'float .5' => .5,
  58. // array data
  59. 'empty array' => array(),
  60. 'int indexed array' => $index_array,
  61. 'associative array' => $assoc_array,
  62. 'nested arrays' => array('foo', $index_array, $assoc_array),
  63. // null data
  64. 'uppercase NULL' => NULL,
  65. 'lowercase null' => null,
  66. // boolean data
  67. 'lowercase true' => true,
  68. 'lowercase false' =>false,
  69. 'uppercase TRUE' =>TRUE,
  70. 'uppercase FALSE' =>FALSE,
  71. // empty data
  72. 'empty string DQ' => "",
  73. 'empty string SQ' => '',
  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. //resource
  82. 'resource' => $res,
  83. );
  84. // loop through each element of the array for pattern
  85. foreach($inputs as $key =>$value) {
  86. echo "\n--$key--\n";
  87. var_dump( class_uses($class, $value) );
  88. };
  89. fclose($res);
  90. ?>
  91. ===DONE===
  92. --EXPECTF--
  93. *** Testing class_uses() : variation ***
  94. --int 0--
  95. array(1) {
  96. ["foo"]=>
  97. string(3) "foo"
  98. }
  99. --int 1--
  100. array(1) {
  101. ["foo"]=>
  102. string(3) "foo"
  103. }
  104. --int 12345--
  105. array(1) {
  106. ["foo"]=>
  107. string(3) "foo"
  108. }
  109. --int -12345--
  110. array(1) {
  111. ["foo"]=>
  112. string(3) "foo"
  113. }
  114. --float 10.5--
  115. array(1) {
  116. ["foo"]=>
  117. string(3) "foo"
  118. }
  119. --float -10.5--
  120. array(1) {
  121. ["foo"]=>
  122. string(3) "foo"
  123. }
  124. --float 12.3456789000e10--
  125. array(1) {
  126. ["foo"]=>
  127. string(3) "foo"
  128. }
  129. --float -12.3456789000e10--
  130. array(1) {
  131. ["foo"]=>
  132. string(3) "foo"
  133. }
  134. --float .5--
  135. array(1) {
  136. ["foo"]=>
  137. string(3) "foo"
  138. }
  139. --empty array--
  140. Error: 2 - class_uses() expects parameter 2 to be boolean, array given, %s(%d)
  141. bool(false)
  142. --int indexed array--
  143. Error: 2 - class_uses() expects parameter 2 to be boolean, array given, %s(%d)
  144. bool(false)
  145. --associative array--
  146. Error: 2 - class_uses() expects parameter 2 to be boolean, array given, %s(%d)
  147. bool(false)
  148. --nested arrays--
  149. Error: 2 - class_uses() expects parameter 2 to be boolean, array given, %s(%d)
  150. bool(false)
  151. --uppercase NULL--
  152. array(1) {
  153. ["foo"]=>
  154. string(3) "foo"
  155. }
  156. --lowercase null--
  157. array(1) {
  158. ["foo"]=>
  159. string(3) "foo"
  160. }
  161. --lowercase true--
  162. array(1) {
  163. ["foo"]=>
  164. string(3) "foo"
  165. }
  166. --lowercase false--
  167. array(1) {
  168. ["foo"]=>
  169. string(3) "foo"
  170. }
  171. --uppercase TRUE--
  172. array(1) {
  173. ["foo"]=>
  174. string(3) "foo"
  175. }
  176. --uppercase FALSE--
  177. array(1) {
  178. ["foo"]=>
  179. string(3) "foo"
  180. }
  181. --empty string DQ--
  182. array(1) {
  183. ["foo"]=>
  184. string(3) "foo"
  185. }
  186. --empty string SQ--
  187. array(1) {
  188. ["foo"]=>
  189. string(3) "foo"
  190. }
  191. --instance of classWithToString--
  192. Error: 2 - class_uses() expects parameter 2 to be boolean, object given, %s(%d)
  193. bool(false)
  194. --instance of classWithoutToString--
  195. Error: 2 - class_uses() expects parameter 2 to be boolean, object given, %s(%d)
  196. bool(false)
  197. --undefined var--
  198. array(1) {
  199. ["foo"]=>
  200. string(3) "foo"
  201. }
  202. --unset var--
  203. array(1) {
  204. ["foo"]=>
  205. string(3) "foo"
  206. }
  207. --resource--
  208. Error: 2 - class_uses() expects parameter 2 to be boolean, resource given, %s(%d)
  209. bool(false)
  210. ===DONE===