fmod_variation2.phpt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. --TEST--
  2. Test fmod() function : usage variations - different data types as $y argument
  3. --FILE--
  4. <?php
  5. /* Prototype : float fmod ( float $x , float $y )
  6. * Description: Returns the floating point remainder (modulo) of the division of the arguments.
  7. * Source code: ext/standard/math.c
  8. */
  9. echo "*** Testing fmod() : usage variations ***\n";
  10. //get an unset variable
  11. $unset_var = 10;
  12. unset ($unset_var);
  13. // heredoc string
  14. $heredoc = <<<EOT
  15. abc
  16. xyz
  17. EOT;
  18. // get a class
  19. class classA
  20. {
  21. }
  22. // get a resource variable
  23. $fp = fopen(__FILE__, "r");
  24. $inputs = array(
  25. // int data
  26. /*1*/ 0,
  27. 1,
  28. 12345,
  29. -2345,
  30. 2147483647,
  31. // float data
  32. /*6*/ 10.5,
  33. -10.5,
  34. 12.3456789000e10,
  35. 12.3456789000E-10,
  36. .5,
  37. // null data
  38. /*11*/ NULL,
  39. null,
  40. // boolean data
  41. /*13*/ true,
  42. false,
  43. TRUE,
  44. FALSE,
  45. // empty data
  46. /*17*/ "",
  47. '',
  48. array(),
  49. // string data
  50. /*20*/ "abcxyz",
  51. 'abcxyz',
  52. $heredoc,
  53. // object data
  54. /*23*/ new classA(),
  55. // undefined data
  56. /*24*/ @$undefined_var,
  57. // unset data
  58. /*25*/ @$unset_var,
  59. // resource variable
  60. /*26*/ $fp
  61. );
  62. // loop through each element of $inputs to check the behaviour of fmod()
  63. $iterator = 1;
  64. foreach($inputs as $input) {
  65. echo "\n-- Iteration $iterator --\n";
  66. var_dump(fmod(123456, $input));
  67. $iterator++;
  68. };
  69. fclose($fp);
  70. ?>
  71. ===Done===
  72. --EXPECTF--
  73. *** Testing fmod() : usage variations ***
  74. -- Iteration 1 --
  75. float(NAN)
  76. -- Iteration 2 --
  77. float(0)
  78. -- Iteration 3 --
  79. float(6)
  80. -- Iteration 4 --
  81. float(1516)
  82. -- Iteration 5 --
  83. float(123456)
  84. -- Iteration 6 --
  85. float(7.5)
  86. -- Iteration 7 --
  87. float(7.5)
  88. -- Iteration 8 --
  89. float(123456)
  90. -- Iteration 9 --
  91. float(2.3605615109341E-10)
  92. -- Iteration 10 --
  93. float(0)
  94. -- Iteration 11 --
  95. float(NAN)
  96. -- Iteration 12 --
  97. float(NAN)
  98. -- Iteration 13 --
  99. float(0)
  100. -- Iteration 14 --
  101. float(NAN)
  102. -- Iteration 15 --
  103. float(0)
  104. -- Iteration 16 --
  105. float(NAN)
  106. -- Iteration 17 --
  107. Warning: fmod() expects parameter 2 to be double, string given in %s on line %d
  108. NULL
  109. -- Iteration 18 --
  110. Warning: fmod() expects parameter 2 to be double, string given in %s on line %d
  111. NULL
  112. -- Iteration 19 --
  113. Warning: fmod() expects parameter 2 to be double, array given in %s on line %d
  114. NULL
  115. -- Iteration 20 --
  116. Warning: fmod() expects parameter 2 to be double, string given in %s on line %d
  117. NULL
  118. -- Iteration 21 --
  119. Warning: fmod() expects parameter 2 to be double, string given in %s on line %d
  120. NULL
  121. -- Iteration 22 --
  122. Warning: fmod() expects parameter 2 to be double, string given in %s on line %d
  123. NULL
  124. -- Iteration 23 --
  125. Warning: fmod() expects parameter 2 to be double, object given in %s on line %d
  126. NULL
  127. -- Iteration 24 --
  128. float(NAN)
  129. -- Iteration 25 --
  130. float(NAN)
  131. -- Iteration 26 --
  132. Warning: fmod() expects parameter 2 to be double, resource given in %s on line %d
  133. NULL
  134. ===Done===