class_implements_variation1.phpt 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. --TEST--
  2. SPL: Test class_implements() function : variation
  3. --FILE--
  4. <?php
  5. echo "*** Testing class_implements() : variation ***\n";
  6. // Define error handler
  7. function test_error_handler($err_no, $err_msg, $filename, $linenum) {
  8. if (error_reporting() & $err_no) {
  9. // report non-silenced errors
  10. echo "Error: $err_no - $err_msg, $filename($linenum)\n";
  11. }
  12. }
  13. set_error_handler('test_error_handler');
  14. // Initialise function arguments not being substituted (if any)
  15. $autoload = true;
  16. //resource
  17. $res = fopen(__FILE__,'r');
  18. //get an unset variable
  19. $unset_var = 10;
  20. unset ($unset_var);
  21. // define some classes
  22. class classWithToString
  23. {
  24. public function __toString() {
  25. return "Class A object";
  26. }
  27. }
  28. class classWithoutToString
  29. {
  30. }
  31. // heredoc string
  32. $heredoc = <<<EOT
  33. hello world
  34. EOT;
  35. // add arrays
  36. $index_array = array (1, 2, 3);
  37. $assoc_array = array ('one' => 1, 'two' => 2);
  38. //array of values to iterate over
  39. $inputs = array(
  40. // int data
  41. 'int 0' => 0,
  42. 'int 1' => 1,
  43. 'int 12345' => 12345,
  44. 'int -12345' => -2345,
  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. // object data
  68. 'instance of classWithToString' => new classWithToString(),
  69. 'instance of classWithoutToString' => new classWithoutToString(),
  70. // undefined data
  71. 'undefined var' => @$undefined_var,
  72. // unset data
  73. 'unset var' => @$unset_var,
  74. //resource
  75. 'resource' => $res,
  76. );
  77. // loop through each element of the array for pattern
  78. foreach($inputs as $key =>$value) {
  79. echo "\n--$key--\n";
  80. try {
  81. var_dump( class_implements($value, $autoload) );
  82. } catch (\TypeError $e) {
  83. echo $e->getMessage() . \PHP_EOL;
  84. }
  85. };
  86. fclose($res);
  87. ?>
  88. --EXPECTF--
  89. *** Testing class_implements() : variation ***
  90. --int 0--
  91. class_implements(): Argument #1 ($object_or_class) must be of type object|string, int given
  92. --int 1--
  93. class_implements(): Argument #1 ($object_or_class) must be of type object|string, int given
  94. --int 12345--
  95. class_implements(): Argument #1 ($object_or_class) must be of type object|string, int given
  96. --int -12345--
  97. class_implements(): Argument #1 ($object_or_class) must be of type object|string, int given
  98. --float 10.5--
  99. class_implements(): Argument #1 ($object_or_class) must be of type object|string, float given
  100. --float -10.5--
  101. class_implements(): Argument #1 ($object_or_class) must be of type object|string, float given
  102. --float 12.3456789000e10--
  103. class_implements(): Argument #1 ($object_or_class) must be of type object|string, float given
  104. --float -12.3456789000e10--
  105. class_implements(): Argument #1 ($object_or_class) must be of type object|string, float given
  106. --float .5--
  107. class_implements(): Argument #1 ($object_or_class) must be of type object|string, float given
  108. --empty array--
  109. class_implements(): Argument #1 ($object_or_class) must be of type object|string, array given
  110. --int indexed array--
  111. class_implements(): Argument #1 ($object_or_class) must be of type object|string, array given
  112. --associative array--
  113. class_implements(): Argument #1 ($object_or_class) must be of type object|string, array given
  114. --nested arrays--
  115. class_implements(): Argument #1 ($object_or_class) must be of type object|string, array given
  116. --uppercase NULL--
  117. class_implements(): Argument #1 ($object_or_class) must be of type object|string, null given
  118. --lowercase null--
  119. class_implements(): Argument #1 ($object_or_class) must be of type object|string, null given
  120. --lowercase true--
  121. class_implements(): Argument #1 ($object_or_class) must be of type object|string, bool given
  122. --lowercase false--
  123. class_implements(): Argument #1 ($object_or_class) must be of type object|string, bool given
  124. --uppercase TRUE--
  125. class_implements(): Argument #1 ($object_or_class) must be of type object|string, bool given
  126. --uppercase FALSE--
  127. class_implements(): Argument #1 ($object_or_class) must be of type object|string, bool given
  128. --empty string DQ--
  129. Error: 2 - class_implements(): Class does not exist and could not be loaded, %s(%d)
  130. bool(false)
  131. --empty string SQ--
  132. Error: 2 - class_implements(): Class does not exist and could not be loaded, %s(%d)
  133. bool(false)
  134. --instance of classWithToString--
  135. array(1) {
  136. ["Stringable"]=>
  137. string(10) "Stringable"
  138. }
  139. --instance of classWithoutToString--
  140. array(0) {
  141. }
  142. --undefined var--
  143. class_implements(): Argument #1 ($object_or_class) must be of type object|string, null given
  144. --unset var--
  145. class_implements(): Argument #1 ($object_or_class) must be of type object|string, null given
  146. --resource--
  147. class_implements(): Argument #1 ($object_or_class) must be of type object|string, resource given