123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658 |
- --TEST--
- Test localtime() function : usage variation - Passing unexpected values to first argument 'timestamp'.
- --FILE--
- <?php
- /* Prototype : array localtime([int timestamp [, bool associative_array]])
- * Description: Returns the results of the C system call localtime as an associative array
- * if the associative_array argument is set to 1 other wise it is a regular array
- * Source code: ext/date/php_date.c
- * Alias to functions:
- */
- echo "*** Testing localtime() : usage variation ***\n";
- date_default_timezone_set("UTC");
- // Initialise function arguments not being substituted (if any)
- $is_associative = true;
- //get an unset variable
- $unset_var = 10;
- unset ($unset_var);
- // define some classes
- class classWithToString
- {
- public function __toString() {
- return "Class A object";
- }
- }
- class classWithoutToString
- {
- }
- // heredoc string
- $heredoc = <<<EOT
- hello world
- EOT;
- // add arrays
- $index_array = array (1, 2, 3);
- $assoc_array = array ('one' => 1, 'two' => 2);
- //array of values to iterate over
- $inputs = array(
- // float data
- 'float 10.5' => 10.5,
- 'float -10.5' => -10.5,
- 'float .5' => .5,
- // array data
- 'empty array' => array(),
- 'int indexed array' => $index_array,
- 'associative array' => $assoc_array,
- 'nested arrays' => array('foo', $index_array, $assoc_array),
- // null data
- 'uppercase NULL' => NULL,
- 'lowercase null' => null,
- // boolean data
- 'lowercase true' => true,
- 'lowercase false' =>false,
- 'uppercase TRUE' =>TRUE,
- 'uppercase FALSE' =>FALSE,
- // empty data
- 'empty string DQ' => "",
- 'empty string SQ' => '',
- // string data
- 'string DQ' => "string",
- 'string SQ' => 'string',
- 'mixed case string' => "sTrInG",
- 'heredoc' => $heredoc,
- // object data
- 'instance of classWithToString' => new classWithToString(),
- 'instance of classWithoutToString' => new classWithoutToString(),
- // undefined data
- 'undefined var' => @$undefined_var,
- // unset data
- 'unset var' => @$unset_var,
- );
- // loop through each element of the array for timestamp
- foreach($inputs as $key =>$value) {
- echo "\n--$key--\n";
- var_dump( localtime($value) );
- var_dump( localtime($value, $is_associative) );
- };
- ?>
- ===DONE===
- --EXPECTF--
- *** Testing localtime() : usage variation ***
- --float 10.5--
- array(9) {
- [0]=>
- int(10)
- [1]=>
- int(0)
- [2]=>
- int(0)
- [3]=>
- int(1)
- [4]=>
- int(0)
- [5]=>
- int(70)
- [6]=>
- int(4)
- [7]=>
- int(0)
- [8]=>
- int(0)
- }
- array(9) {
- ["tm_sec"]=>
- int(10)
- ["tm_min"]=>
- int(0)
- ["tm_hour"]=>
- int(0)
- ["tm_mday"]=>
- int(1)
- ["tm_mon"]=>
- int(0)
- ["tm_year"]=>
- int(70)
- ["tm_wday"]=>
- int(4)
- ["tm_yday"]=>
- int(0)
- ["tm_isdst"]=>
- int(0)
- }
- --float -10.5--
- array(9) {
- [0]=>
- int(50)
- [1]=>
- int(59)
- [2]=>
- int(23)
- [3]=>
- int(31)
- [4]=>
- int(11)
- [5]=>
- int(69)
- [6]=>
- int(3)
- [7]=>
- int(364)
- [8]=>
- int(0)
- }
- array(9) {
- ["tm_sec"]=>
- int(50)
- ["tm_min"]=>
- int(59)
- ["tm_hour"]=>
- int(23)
- ["tm_mday"]=>
- int(31)
- ["tm_mon"]=>
- int(11)
- ["tm_year"]=>
- int(69)
- ["tm_wday"]=>
- int(3)
- ["tm_yday"]=>
- int(364)
- ["tm_isdst"]=>
- int(0)
- }
- --float .5--
- array(9) {
- [0]=>
- int(0)
- [1]=>
- int(0)
- [2]=>
- int(0)
- [3]=>
- int(1)
- [4]=>
- int(0)
- [5]=>
- int(70)
- [6]=>
- int(4)
- [7]=>
- int(0)
- [8]=>
- int(0)
- }
- array(9) {
- ["tm_sec"]=>
- int(0)
- ["tm_min"]=>
- int(0)
- ["tm_hour"]=>
- int(0)
- ["tm_mday"]=>
- int(1)
- ["tm_mon"]=>
- int(0)
- ["tm_year"]=>
- int(70)
- ["tm_wday"]=>
- int(4)
- ["tm_yday"]=>
- int(0)
- ["tm_isdst"]=>
- int(0)
- }
- --empty array--
- Warning: localtime() expects parameter 1 to be long, array given in %s on line %d
- bool(false)
- Warning: localtime() expects parameter 1 to be long, array given in %s on line %d
- bool(false)
- --int indexed array--
- Warning: localtime() expects parameter 1 to be long, array given in %s on line %d
- bool(false)
- Warning: localtime() expects parameter 1 to be long, array given in %s on line %d
- bool(false)
- --associative array--
- Warning: localtime() expects parameter 1 to be long, array given in %s on line %d
- bool(false)
- Warning: localtime() expects parameter 1 to be long, array given in %s on line %d
- bool(false)
- --nested arrays--
- Warning: localtime() expects parameter 1 to be long, array given in %s on line %d
- bool(false)
- Warning: localtime() expects parameter 1 to be long, array given in %s on line %d
- bool(false)
- --uppercase NULL--
- array(9) {
- [0]=>
- int(0)
- [1]=>
- int(0)
- [2]=>
- int(0)
- [3]=>
- int(1)
- [4]=>
- int(0)
- [5]=>
- int(70)
- [6]=>
- int(4)
- [7]=>
- int(0)
- [8]=>
- int(0)
- }
- array(9) {
- ["tm_sec"]=>
- int(0)
- ["tm_min"]=>
- int(0)
- ["tm_hour"]=>
- int(0)
- ["tm_mday"]=>
- int(1)
- ["tm_mon"]=>
- int(0)
- ["tm_year"]=>
- int(70)
- ["tm_wday"]=>
- int(4)
- ["tm_yday"]=>
- int(0)
- ["tm_isdst"]=>
- int(0)
- }
- --lowercase null--
- array(9) {
- [0]=>
- int(0)
- [1]=>
- int(0)
- [2]=>
- int(0)
- [3]=>
- int(1)
- [4]=>
- int(0)
- [5]=>
- int(70)
- [6]=>
- int(4)
- [7]=>
- int(0)
- [8]=>
- int(0)
- }
- array(9) {
- ["tm_sec"]=>
- int(0)
- ["tm_min"]=>
- int(0)
- ["tm_hour"]=>
- int(0)
- ["tm_mday"]=>
- int(1)
- ["tm_mon"]=>
- int(0)
- ["tm_year"]=>
- int(70)
- ["tm_wday"]=>
- int(4)
- ["tm_yday"]=>
- int(0)
- ["tm_isdst"]=>
- int(0)
- }
- --lowercase true--
- array(9) {
- [0]=>
- int(1)
- [1]=>
- int(0)
- [2]=>
- int(0)
- [3]=>
- int(1)
- [4]=>
- int(0)
- [5]=>
- int(70)
- [6]=>
- int(4)
- [7]=>
- int(0)
- [8]=>
- int(0)
- }
- array(9) {
- ["tm_sec"]=>
- int(1)
- ["tm_min"]=>
- int(0)
- ["tm_hour"]=>
- int(0)
- ["tm_mday"]=>
- int(1)
- ["tm_mon"]=>
- int(0)
- ["tm_year"]=>
- int(70)
- ["tm_wday"]=>
- int(4)
- ["tm_yday"]=>
- int(0)
- ["tm_isdst"]=>
- int(0)
- }
- --lowercase false--
- array(9) {
- [0]=>
- int(0)
- [1]=>
- int(0)
- [2]=>
- int(0)
- [3]=>
- int(1)
- [4]=>
- int(0)
- [5]=>
- int(70)
- [6]=>
- int(4)
- [7]=>
- int(0)
- [8]=>
- int(0)
- }
- array(9) {
- ["tm_sec"]=>
- int(0)
- ["tm_min"]=>
- int(0)
- ["tm_hour"]=>
- int(0)
- ["tm_mday"]=>
- int(1)
- ["tm_mon"]=>
- int(0)
- ["tm_year"]=>
- int(70)
- ["tm_wday"]=>
- int(4)
- ["tm_yday"]=>
- int(0)
- ["tm_isdst"]=>
- int(0)
- }
- --uppercase TRUE--
- array(9) {
- [0]=>
- int(1)
- [1]=>
- int(0)
- [2]=>
- int(0)
- [3]=>
- int(1)
- [4]=>
- int(0)
- [5]=>
- int(70)
- [6]=>
- int(4)
- [7]=>
- int(0)
- [8]=>
- int(0)
- }
- array(9) {
- ["tm_sec"]=>
- int(1)
- ["tm_min"]=>
- int(0)
- ["tm_hour"]=>
- int(0)
- ["tm_mday"]=>
- int(1)
- ["tm_mon"]=>
- int(0)
- ["tm_year"]=>
- int(70)
- ["tm_wday"]=>
- int(4)
- ["tm_yday"]=>
- int(0)
- ["tm_isdst"]=>
- int(0)
- }
- --uppercase FALSE--
- array(9) {
- [0]=>
- int(0)
- [1]=>
- int(0)
- [2]=>
- int(0)
- [3]=>
- int(1)
- [4]=>
- int(0)
- [5]=>
- int(70)
- [6]=>
- int(4)
- [7]=>
- int(0)
- [8]=>
- int(0)
- }
- array(9) {
- ["tm_sec"]=>
- int(0)
- ["tm_min"]=>
- int(0)
- ["tm_hour"]=>
- int(0)
- ["tm_mday"]=>
- int(1)
- ["tm_mon"]=>
- int(0)
- ["tm_year"]=>
- int(70)
- ["tm_wday"]=>
- int(4)
- ["tm_yday"]=>
- int(0)
- ["tm_isdst"]=>
- int(0)
- }
- --empty string DQ--
- Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
- bool(false)
- Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
- bool(false)
- --empty string SQ--
- Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
- bool(false)
- Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
- bool(false)
- --string DQ--
- Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
- bool(false)
- Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
- bool(false)
- --string SQ--
- Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
- bool(false)
- Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
- bool(false)
- --mixed case string--
- Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
- bool(false)
- Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
- bool(false)
- --heredoc--
- Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
- bool(false)
- Warning: localtime() expects parameter 1 to be long, string given in %s on line %d
- bool(false)
- --instance of classWithToString--
- Warning: localtime() expects parameter 1 to be long, object given in %s on line %d
- bool(false)
- Warning: localtime() expects parameter 1 to be long, object given in %s on line %d
- bool(false)
- --instance of classWithoutToString--
- Warning: localtime() expects parameter 1 to be long, object given in %s on line %d
- bool(false)
- Warning: localtime() expects parameter 1 to be long, object given in %s on line %d
- bool(false)
- --undefined var--
- array(9) {
- [0]=>
- int(0)
- [1]=>
- int(0)
- [2]=>
- int(0)
- [3]=>
- int(1)
- [4]=>
- int(0)
- [5]=>
- int(70)
- [6]=>
- int(4)
- [7]=>
- int(0)
- [8]=>
- int(0)
- }
- array(9) {
- ["tm_sec"]=>
- int(0)
- ["tm_min"]=>
- int(0)
- ["tm_hour"]=>
- int(0)
- ["tm_mday"]=>
- int(1)
- ["tm_mon"]=>
- int(0)
- ["tm_year"]=>
- int(70)
- ["tm_wday"]=>
- int(4)
- ["tm_yday"]=>
- int(0)
- ["tm_isdst"]=>
- int(0)
- }
- --unset var--
- array(9) {
- [0]=>
- int(0)
- [1]=>
- int(0)
- [2]=>
- int(0)
- [3]=>
- int(1)
- [4]=>
- int(0)
- [5]=>
- int(70)
- [6]=>
- int(4)
- [7]=>
- int(0)
- [8]=>
- int(0)
- }
- array(9) {
- ["tm_sec"]=>
- int(0)
- ["tm_min"]=>
- int(0)
- ["tm_hour"]=>
- int(0)
- ["tm_mday"]=>
- int(1)
- ["tm_mon"]=>
- int(0)
- ["tm_year"]=>
- int(70)
- ["tm_wday"]=>
- int(4)
- ["tm_yday"]=>
- int(0)
- ["tm_isdst"]=>
- int(0)
- }
- ===DONE===
|