gmstrftime_variation1.phpt 4.4 KB

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