checkdate_variation3.phpt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. --TEST--
  2. Test checkdate() function : usage variation - Passing unexpected values to third argument $year.
  3. --FILE--
  4. <?php
  5. /* Prototype : bool checkdate ( int $month , int $day , int $year )
  6. * Description: Checks the validity of the date formed by the arguments.
  7. * A date is considered valid if each parameter is properly defined.
  8. * Source code: ext/date/php_date.c
  9. */
  10. echo "*** Testing checkdate() : usage variation - unexpected values to third argument \$year***\n";
  11. //get an unset variable
  12. $unset_var = 10;
  13. unset ($unset_var);
  14. // define some classes
  15. class classWithToString
  16. {
  17. public function __toString() {
  18. return "Class A object";
  19. }
  20. }
  21. class classWithoutToString
  22. {
  23. }
  24. // heredoc string
  25. $heredoc = <<<EOT
  26. hello world
  27. EOT;
  28. // add arrays
  29. $index_array = array (1, 2, 3);
  30. $assoc_array = array ('one' => 1, 'two' => 2);
  31. // resource
  32. $file_handle = fopen(__FILE__, 'r');
  33. //array of values to iterate over
  34. $inputs = array(
  35. // float data
  36. 'float 10.5' => 10.5,
  37. 'float -10.5' => -10.5,
  38. 'float .5' => .5,
  39. // array data
  40. 'empty array' => array(),
  41. 'int indexed array' => $index_array,
  42. 'associative array' => $assoc_array,
  43. 'nested arrays' => array('foo', $index_array, $assoc_array),
  44. // null data
  45. 'uppercase NULL' => NULL,
  46. 'lowercase null' => null,
  47. // boolean data
  48. 'lowercase true' => true,
  49. 'lowercase false' =>false,
  50. 'uppercase TRUE' =>TRUE,
  51. 'uppercase FALSE' =>FALSE,
  52. // empty data
  53. 'empty string DQ' => "",
  54. 'empty string SQ' => '',
  55. // string data
  56. 'string DQ' => "string",
  57. 'string SQ' => 'string',
  58. 'mixed case string' => "sTrInG",
  59. 'heredoc' => $heredoc,
  60. // object data
  61. 'instance of classWithToString' => new classWithToString(),
  62. 'instance of classWithoutToString' => new classWithoutToString(),
  63. // undefined data
  64. 'undefined var' => @$undefined_var,
  65. // unset data
  66. 'unset var' => @$unset_var,
  67. // resource
  68. 'resource' => $file_handle
  69. );
  70. $day = 2;
  71. $month = 7;
  72. foreach($inputs as $variation =>$year) {
  73. echo "\n-- $variation --\n";
  74. var_dump( checkdate($month, $day, $year) );
  75. };
  76. // closing the resource
  77. fclose( $file_handle);
  78. ?>
  79. ===DONE===
  80. --EXPECTF--
  81. *** Testing checkdate() : usage variation - unexpected values to third argument $year***
  82. -- float 10.5 --
  83. bool(true)
  84. -- float -10.5 --
  85. bool(false)
  86. -- float .5 --
  87. bool(false)
  88. -- empty array --
  89. Warning: checkdate() expects parameter 3 to be long, array given in %s on line %d
  90. bool(false)
  91. -- int indexed array --
  92. Warning: checkdate() expects parameter 3 to be long, array given in %s on line %d
  93. bool(false)
  94. -- associative array --
  95. Warning: checkdate() expects parameter 3 to be long, array given in %s on line %d
  96. bool(false)
  97. -- nested arrays --
  98. Warning: checkdate() expects parameter 3 to be long, array given in %s on line %d
  99. bool(false)
  100. -- uppercase NULL --
  101. bool(false)
  102. -- lowercase null --
  103. bool(false)
  104. -- lowercase true --
  105. bool(true)
  106. -- lowercase false --
  107. bool(false)
  108. -- uppercase TRUE --
  109. bool(true)
  110. -- uppercase FALSE --
  111. bool(false)
  112. -- empty string DQ --
  113. Warning: checkdate() expects parameter 3 to be long, string given in %s on line %d
  114. bool(false)
  115. -- empty string SQ --
  116. Warning: checkdate() expects parameter 3 to be long, string given in %s on line %d
  117. bool(false)
  118. -- string DQ --
  119. Warning: checkdate() expects parameter 3 to be long, string given in %s on line %d
  120. bool(false)
  121. -- string SQ --
  122. Warning: checkdate() expects parameter 3 to be long, string given in %s on line %d
  123. bool(false)
  124. -- mixed case string --
  125. Warning: checkdate() expects parameter 3 to be long, string given in %s on line %d
  126. bool(false)
  127. -- heredoc --
  128. Warning: checkdate() expects parameter 3 to be long, string given in %s on line %d
  129. bool(false)
  130. -- instance of classWithToString --
  131. Warning: checkdate() expects parameter 3 to be long, object given in %s on line %d
  132. bool(false)
  133. -- instance of classWithoutToString --
  134. Warning: checkdate() expects parameter 3 to be long, object given in %s on line %d
  135. bool(false)
  136. -- undefined var --
  137. bool(false)
  138. -- unset var --
  139. bool(false)
  140. -- resource --
  141. Warning: checkdate() expects parameter 3 to be long, resource given in %s on line %d
  142. bool(false)
  143. ===DONE===