class_implements_variation1.phpt 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. --TEST--
  2. SPL: Test class_implements() function : variation
  3. --FILE--
  4. <?php
  5. /* Prototype : array class_implements(mixed what [, bool autoload ])
  6. * Description: Return all classes and interfaces implemented by SPL
  7. * Source code: ext/spl/php_spl.c
  8. * Alias to functions:
  9. */
  10. echo "*** Testing class_implements() : 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 (if any)
  20. $autoload = true;
  21. //resource
  22. $res = fopen(__FILE__,'r');
  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. // int data
  46. 'int 0' => 0,
  47. 'int 1' => 1,
  48. 'int 12345' => 12345,
  49. 'int -12345' => -2345,
  50. // float data
  51. 'float 10.5' => 10.5,
  52. 'float -10.5' => -10.5,
  53. 'float 12.3456789000e10' => 12.3456789000e10,
  54. 'float -12.3456789000e10' => -12.3456789000e10,
  55. 'float .5' => .5,
  56. // array data
  57. 'empty array' => array(),
  58. 'int indexed array' => $index_array,
  59. 'associative array' => $assoc_array,
  60. 'nested arrays' => array('foo', $index_array, $assoc_array),
  61. // null data
  62. 'uppercase NULL' => NULL,
  63. 'lowercase null' => null,
  64. // boolean data
  65. 'lowercase true' => true,
  66. 'lowercase false' =>false,
  67. 'uppercase TRUE' =>TRUE,
  68. 'uppercase FALSE' =>FALSE,
  69. // empty data
  70. 'empty string DQ' => "",
  71. 'empty string SQ' => '',
  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. //resource
  80. 'resource' => $res,
  81. );
  82. // loop through each element of the array for pattern
  83. foreach($inputs as $key =>$value) {
  84. echo "\n--$key--\n";
  85. var_dump( class_implements($value, $autoload) );
  86. };
  87. fclose($res);
  88. ?>
  89. ===DONE===
  90. --EXPECTF--
  91. *** Testing class_implements() : variation ***
  92. --int 0--
  93. Error: 2 - class_implements(): object or string expected, %s(%d)
  94. bool(false)
  95. --int 1--
  96. Error: 2 - class_implements(): object or string expected, %s(%d)
  97. bool(false)
  98. --int 12345--
  99. Error: 2 - class_implements(): object or string expected, %s(%d)
  100. bool(false)
  101. --int -12345--
  102. Error: 2 - class_implements(): object or string expected, %s(%d)
  103. bool(false)
  104. --float 10.5--
  105. Error: 2 - class_implements(): object or string expected, %s(%d)
  106. bool(false)
  107. --float -10.5--
  108. Error: 2 - class_implements(): object or string expected, %s(%d)
  109. bool(false)
  110. --float 12.3456789000e10--
  111. Error: 2 - class_implements(): object or string expected, %s(%d)
  112. bool(false)
  113. --float -12.3456789000e10--
  114. Error: 2 - class_implements(): object or string expected, %s(%d)
  115. bool(false)
  116. --float .5--
  117. Error: 2 - class_implements(): object or string expected, %s(%d)
  118. bool(false)
  119. --empty array--
  120. Error: 2 - class_implements(): object or string expected, %s(%d)
  121. bool(false)
  122. --int indexed array--
  123. Error: 2 - class_implements(): object or string expected, %s(%d)
  124. bool(false)
  125. --associative array--
  126. Error: 2 - class_implements(): object or string expected, %s(%d)
  127. bool(false)
  128. --nested arrays--
  129. Error: 2 - class_implements(): object or string expected, %s(%d)
  130. bool(false)
  131. --uppercase NULL--
  132. Error: 2 - class_implements(): object or string expected, %s(%d)
  133. bool(false)
  134. --lowercase null--
  135. Error: 2 - class_implements(): object or string expected, %s(%d)
  136. bool(false)
  137. --lowercase true--
  138. Error: 2 - class_implements(): object or string expected, %s(%d)
  139. bool(false)
  140. --lowercase false--
  141. Error: 2 - class_implements(): object or string expected, %s(%d)
  142. bool(false)
  143. --uppercase TRUE--
  144. Error: 2 - class_implements(): object or string expected, %s(%d)
  145. bool(false)
  146. --uppercase FALSE--
  147. Error: 2 - class_implements(): object or string expected, %s(%d)
  148. bool(false)
  149. --empty string DQ--
  150. Error: 2 - class_implements(): Class does not exist and could not be loaded, %s(%d)
  151. bool(false)
  152. --empty string SQ--
  153. Error: 2 - class_implements(): Class does not exist and could not be loaded, %s(%d)
  154. bool(false)
  155. --instance of classWithToString--
  156. array(0) {
  157. }
  158. --instance of classWithoutToString--
  159. array(0) {
  160. }
  161. --undefined var--
  162. Error: 2 - class_implements(): object or string expected, %s(%d)
  163. bool(false)
  164. --unset var--
  165. Error: 2 - class_implements(): object or string expected, %s(%d)
  166. bool(false)
  167. --resource--
  168. Error: 2 - class_implements(): object or string expected, %s(%d)
  169. bool(false)
  170. ===DONE===