strftime_variation1.phpt 4.3 KB

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