gmstrftime_variation2.phpt 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. --TEST--
  2. Test gmstrftime() function : usage variation - Passing unexpected values to second argument 'timestamp'.
  3. --SKIPIF--
  4. <?php
  5. if(PHP_INT_SIZE != 4 ) {
  6. die("skip Test is not valid for 64-bit");
  7. }
  8. ?>
  9. --FILE--
  10. <?php
  11. /* Prototype : string gmstrftime(string format [, int timestamp])
  12. * Description: Format a GMT/UCT time/date according to locale settings
  13. * Source code: ext/date/php_date.c
  14. * Alias to functions:
  15. */
  16. echo "*** Testing gmstrftime() : usage variation ***\n";
  17. date_default_timezone_set("Asia/Calcutta");
  18. // Initialise function arguments not being substituted (if any)
  19. $format = '%b %d %Y %H:%M:%S';
  20. //get an unset variable
  21. $unset_var = 10;
  22. unset ($unset_var);
  23. // define some classes
  24. class classWithToString
  25. {
  26. public function __toString() {
  27. return "Class A object";
  28. }
  29. }
  30. class classWithoutToString
  31. {
  32. }
  33. // heredoc string
  34. $heredoc = <<<EOT
  35. hello world
  36. EOT;
  37. // add arrays
  38. $index_array = array (1, 2, 3);
  39. $assoc_array = array ('one' => 1, 'two' => 2);
  40. //array of values to iterate over
  41. $inputs = array(
  42. // float data
  43. 'float 10.5' => 10.5,
  44. 'float -10.5' => -10.5,
  45. 'float 12.3456789000e10' => 12.3456789000e10,
  46. 'float -12.3456789000e10' => -12.3456789000e10,
  47. 'float .5' => .5,
  48. // array data
  49. 'empty array' => array(),
  50. 'int indexed array' => $index_array,
  51. 'associative array' => $assoc_array,
  52. 'nested arrays' => array('foo', $index_array, $assoc_array),
  53. // null data
  54. 'uppercase NULL' => NULL,
  55. 'lowercase null' => null,
  56. // boolean data
  57. 'lowercase true' => true,
  58. 'lowercase false' =>false,
  59. 'uppercase TRUE' =>TRUE,
  60. 'uppercase FALSE' =>FALSE,
  61. // empty data
  62. 'empty string DQ' => "",
  63. 'empty string SQ' => '',
  64. // string data
  65. 'string DQ' => "string",
  66. 'string SQ' => 'string',
  67. 'mixed case string' => "sTrInG",
  68. 'heredoc' => $heredoc,
  69. // object data
  70. 'instance of classWithToString' => new classWithToString(),
  71. 'instance of classWithoutToString' => new classWithoutToString(),
  72. // undefined data
  73. 'undefined var' => @$undefined_var,
  74. // unset data
  75. 'unset var' => @$unset_var,
  76. );
  77. // loop through each element of the array for timestamp
  78. foreach($inputs as $key =>$value) {
  79. echo "\n--$key--\n";
  80. var_dump( gmstrftime($format, $value) );
  81. };
  82. ?>
  83. ===DONE===
  84. --EXPECTF--
  85. *** Testing gmstrftime() : usage variation ***
  86. --float 10.5--
  87. string(20) "Jan 01 1970 00:00:10"
  88. --float -10.5--
  89. string(20) "Dec 31 1969 23:59:50"
  90. --float 12.3456789000e10--
  91. string(20) "Mar 26 1935 04:50:16"
  92. --float -12.3456789000e10--
  93. string(20) "Oct 08 2004 19:09:44"
  94. --float .5--
  95. string(20) "Jan 01 1970 00:00:00"
  96. --empty array--
  97. Warning: gmstrftime() expects parameter 2 to be long, array given in %s on line %d
  98. bool(false)
  99. --int indexed array--
  100. Warning: gmstrftime() expects parameter 2 to be long, array given in %s on line %d
  101. bool(false)
  102. --associative array--
  103. Warning: gmstrftime() expects parameter 2 to be long, array given in %s on line %d
  104. bool(false)
  105. --nested arrays--
  106. Warning: gmstrftime() expects parameter 2 to be long, array given in %s on line %d
  107. bool(false)
  108. --uppercase NULL--
  109. string(20) "Jan 01 1970 00:00:00"
  110. --lowercase null--
  111. string(20) "Jan 01 1970 00:00:00"
  112. --lowercase true--
  113. string(20) "Jan 01 1970 00:00:01"
  114. --lowercase false--
  115. string(20) "Jan 01 1970 00:00:00"
  116. --uppercase TRUE--
  117. string(20) "Jan 01 1970 00:00:01"
  118. --uppercase FALSE--
  119. string(20) "Jan 01 1970 00:00:00"
  120. --empty string DQ--
  121. Warning: gmstrftime() expects parameter 2 to be long, string given in %s on line %d
  122. bool(false)
  123. --empty string SQ--
  124. Warning: gmstrftime() expects parameter 2 to be long, string given in %s on line %d
  125. bool(false)
  126. --string DQ--
  127. Warning: gmstrftime() expects parameter 2 to be long, string given in %s on line %d
  128. bool(false)
  129. --string SQ--
  130. Warning: gmstrftime() expects parameter 2 to be long, string given in %s on line %d
  131. bool(false)
  132. --mixed case string--
  133. Warning: gmstrftime() expects parameter 2 to be long, string given in %s on line %d
  134. bool(false)
  135. --heredoc--
  136. Warning: gmstrftime() expects parameter 2 to be long, string given in %s on line %d
  137. bool(false)
  138. --instance of classWithToString--
  139. Warning: gmstrftime() expects parameter 2 to be long, object given in %s on line %d
  140. bool(false)
  141. --instance of classWithoutToString--
  142. Warning: gmstrftime() expects parameter 2 to be long, object given in %s on line %d
  143. bool(false)
  144. --undefined var--
  145. string(20) "Jan 01 1970 00:00:00"
  146. --unset var--
  147. string(20) "Jan 01 1970 00:00:00"
  148. ===DONE===