abs_variation.phpt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. --TEST--
  2. Test abs() function : usage variations - different data types as $number arg
  3. --FILE--
  4. <?php
  5. /*
  6. * Pass different data types as $number argument to abs() to test behaviour
  7. */
  8. echo "*** Testing abs() : usage variations ***\n";
  9. //get an unset variable
  10. $unset_var = 10;
  11. unset ($unset_var);
  12. // get a class
  13. class classA
  14. {
  15. public function __toString() {
  16. return "abs";
  17. }
  18. }
  19. // heredoc string
  20. $heredoc = <<<EOT
  21. abs
  22. EOT;
  23. // get a resource variable
  24. $fp = fopen(__FILE__, "r");
  25. // unexpected values to be passed to $number argument
  26. $inputs = array(
  27. // null data
  28. /*10*/ NULL,
  29. null,
  30. // boolean data
  31. /*12*/ true,
  32. false,
  33. TRUE,
  34. FALSE,
  35. // empty data
  36. /*16*/ "",
  37. '',
  38. array(),
  39. // string data
  40. /*19*/ "abs",
  41. 'abs',
  42. $heredoc,
  43. // object data
  44. /*22*/ new classA(),
  45. // undefined data
  46. /*23*/ @$undefined_var,
  47. // unset data
  48. /*24*/ @$unset_var,
  49. // resource variable
  50. /*25*/ $fp
  51. );
  52. // loop through each element of $inputs to check the behavior of abs()
  53. $iterator = 1;
  54. foreach($inputs as $input) {
  55. echo "\n-- Iteration $iterator --\n";
  56. try {
  57. var_dump(abs($input));
  58. } catch (TypeError $e) {
  59. echo $e->getMessage(), "\n";
  60. }
  61. $iterator++;
  62. };
  63. fclose($fp);
  64. ?>
  65. --EXPECTF--
  66. *** Testing abs() : usage variations ***
  67. -- Iteration 1 --
  68. Deprecated: abs(): Passing null to parameter #1 ($num) of type int|float is deprecated in %s on line %d
  69. int(0)
  70. -- Iteration 2 --
  71. Deprecated: abs(): Passing null to parameter #1 ($num) of type int|float is deprecated in %s on line %d
  72. int(0)
  73. -- Iteration 3 --
  74. int(1)
  75. -- Iteration 4 --
  76. int(0)
  77. -- Iteration 5 --
  78. int(1)
  79. -- Iteration 6 --
  80. int(0)
  81. -- Iteration 7 --
  82. abs(): Argument #1 ($num) must be of type int|float, string given
  83. -- Iteration 8 --
  84. abs(): Argument #1 ($num) must be of type int|float, string given
  85. -- Iteration 9 --
  86. abs(): Argument #1 ($num) must be of type int|float, array given
  87. -- Iteration 10 --
  88. abs(): Argument #1 ($num) must be of type int|float, string given
  89. -- Iteration 11 --
  90. abs(): Argument #1 ($num) must be of type int|float, string given
  91. -- Iteration 12 --
  92. abs(): Argument #1 ($num) must be of type int|float, string given
  93. -- Iteration 13 --
  94. abs(): Argument #1 ($num) must be of type int|float, classA given
  95. -- Iteration 14 --
  96. Deprecated: abs(): Passing null to parameter #1 ($num) of type int|float is deprecated in %s on line %d
  97. int(0)
  98. -- Iteration 15 --
  99. Deprecated: abs(): Passing null to parameter #1 ($num) of type int|float is deprecated in %s on line %d
  100. int(0)
  101. -- Iteration 16 --
  102. abs(): Argument #1 ($num) must be of type int|float, resource given