function_exists_variation1.phpt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. --TEST--
  2. Test function_exists() function : usage variations - test values for $str argument
  3. --FILE--
  4. <?php
  5. /*
  6. * proto bool function_exists(string function_name)
  7. * Function is implemented in Zend/zend_builtin_functions.c
  8. */
  9. echo "*** Testing function_exists() function: with unexpected inputs for 'str' argument ***\n";
  10. //get an unset variable
  11. $unset_var = 'string_val';
  12. unset($unset_var);
  13. //defining a class
  14. class sample {
  15. public function __toString() {
  16. return "sample object";
  17. }
  18. }
  19. //getting the resource
  20. $file_handle = fopen(__FILE__, "r");
  21. // array with different values for $str
  22. $inputs = array (
  23. // integer values
  24. 0,
  25. 1,
  26. 255,
  27. 256,
  28. PHP_INT_MAX,
  29. -PHP_INT_MAX,
  30. // float values
  31. 10.5,
  32. -20.5,
  33. 10.1234567e10,
  34. // array values
  35. array(),
  36. array(0),
  37. array(1, 2),
  38. // boolean values
  39. true,
  40. false,
  41. TRUE,
  42. FALSE,
  43. // null values
  44. NULL,
  45. null,
  46. // objects
  47. new sample(),
  48. // resource
  49. $file_handle,
  50. // undefined variable
  51. @$undefined_var,
  52. // unset variable
  53. @$unset_var
  54. );
  55. // loop through with each element of the $inputs array to test function_exists() function
  56. $count = 1;
  57. foreach($inputs as $input) {
  58. echo "-- Iteration $count --\n";
  59. var_dump( function_exists($input) );
  60. $count ++;
  61. }
  62. fclose($file_handle); //closing the file handle
  63. ?>
  64. ===Done===
  65. --EXPECTF--
  66. *** Testing function_exists() function: with unexpected inputs for 'str' argument ***
  67. -- Iteration 1 --
  68. bool(false)
  69. -- Iteration 2 --
  70. bool(false)
  71. -- Iteration 3 --
  72. bool(false)
  73. -- Iteration 4 --
  74. bool(false)
  75. -- Iteration 5 --
  76. bool(false)
  77. -- Iteration 6 --
  78. bool(false)
  79. -- Iteration 7 --
  80. bool(false)
  81. -- Iteration 8 --
  82. bool(false)
  83. -- Iteration 9 --
  84. bool(false)
  85. -- Iteration 10 --
  86. Warning: function_exists() expects parameter 1 to be string, array given in %s on line %d
  87. NULL
  88. -- Iteration 11 --
  89. Warning: function_exists() expects parameter 1 to be string, array given in %s on line %d
  90. NULL
  91. -- Iteration 12 --
  92. Warning: function_exists() expects parameter 1 to be string, array given in %s on line %d
  93. NULL
  94. -- Iteration 13 --
  95. bool(false)
  96. -- Iteration 14 --
  97. bool(false)
  98. -- Iteration 15 --
  99. bool(false)
  100. -- Iteration 16 --
  101. bool(false)
  102. -- Iteration 17 --
  103. bool(false)
  104. -- Iteration 18 --
  105. bool(false)
  106. -- Iteration 19 --
  107. bool(false)
  108. -- Iteration 20 --
  109. Warning: function_exists() expects parameter 1 to be string, resource given in %s on line %d
  110. NULL
  111. -- Iteration 21 --
  112. bool(false)
  113. -- Iteration 22 --
  114. bool(false)
  115. ===Done===