date_variation1.phpt 4.1 KB

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