@@ -782,14 +782,15 @@ static void php_date(INTERNAL_FUNCTION_PARAMETERS, int localtime)
782
782
{
783
783
zend_string * format ;
784
784
zend_long ts ;
785
+ zend_bool ts_is_null = 1 ;
785
786
786
787
ZEND_PARSE_PARAMETERS_START (1 , 2 )
787
788
Z_PARAM_STR (format )
788
789
Z_PARAM_OPTIONAL
789
- Z_PARAM_LONG (ts )
790
+ Z_PARAM_LONG_OR_NULL (ts , ts_is_null )
790
791
ZEND_PARSE_PARAMETERS_END ();
791
792
792
- if (ZEND_NUM_ARGS () == 1 ) {
793
+ if (ts_is_null ) {
793
794
ts = php_time ();
794
795
}
795
796
@@ -940,21 +941,22 @@ PHP_FUNCTION(gmdate)
940
941
PHP_FUNCTION (idate )
941
942
{
942
943
zend_string * format ;
943
- zend_long ts = 0 ;
944
+ zend_long ts ;
945
+ zend_bool ts_is_null = 1 ;
944
946
int ret ;
945
947
946
948
ZEND_PARSE_PARAMETERS_START (1 , 2 )
947
949
Z_PARAM_STR (format )
948
950
Z_PARAM_OPTIONAL
949
- Z_PARAM_LONG (ts )
951
+ Z_PARAM_LONG_OR_NULL (ts , ts_is_null )
950
952
ZEND_PARSE_PARAMETERS_END ();
951
953
952
954
if (ZSTR_LEN (format ) != 1 ) {
953
955
php_error_docref (NULL , E_WARNING , "idate format is one char" );
954
956
RETURN_FALSE ;
955
957
}
956
958
957
- if (ZEND_NUM_ARGS () == 1 ) {
959
+ if (ts_is_null ) {
958
960
ts = php_time ();
959
961
}
960
962
@@ -1011,14 +1013,15 @@ PHP_FUNCTION(strtotime)
1011
1013
zend_string * times ;
1012
1014
int error1 , error2 ;
1013
1015
timelib_error_container * error ;
1014
- zend_long preset_ts = 0 , ts ;
1016
+ zend_long preset_ts , ts ;
1017
+ zend_bool preset_ts_is_null = 1 ;
1015
1018
timelib_time * t , * now ;
1016
1019
timelib_tzinfo * tzi ;
1017
1020
1018
1021
ZEND_PARSE_PARAMETERS_START (1 , 2 )
1019
1022
Z_PARAM_STR (times )
1020
1023
Z_PARAM_OPTIONAL
1021
- Z_PARAM_LONG (preset_ts )
1024
+ Z_PARAM_LONG_OR_NULL (preset_ts , preset_ts_is_null )
1022
1025
ZEND_PARSE_PARAMETERS_END ();
1023
1026
1024
1027
tzi = get_timezone_info ();
@@ -1027,7 +1030,7 @@ PHP_FUNCTION(strtotime)
1027
1030
now -> tz_info = tzi ;
1028
1031
now -> zone_type = TIMELIB_ZONETYPE_ID ;
1029
1032
timelib_unixtime2local (now ,
1030
- ( ZEND_NUM_ARGS () == 2 ) ? (timelib_sll ) preset_ts : (timelib_sll ) php_time ());
1033
+ ! preset_ts_is_null ? (timelib_sll ) preset_ts : (timelib_sll ) php_time ());
1031
1034
1032
1035
t = timelib_strtotime (ZSTR_VAL (times ), ZSTR_LEN (times ), & error ,
1033
1036
DATE_TIMEZONEDB , php_date_parse_tzfile_wrapper );
@@ -1051,7 +1054,8 @@ PHP_FUNCTION(strtotime)
1051
1054
/* {{{ php_mktime - (gm)mktime helper */
1052
1055
PHPAPI void php_mktime (INTERNAL_FUNCTION_PARAMETERS , int gmt )
1053
1056
{
1054
- zend_long hou = 0 , min = 0 , sec = 0 , mon = 0 , day = 0 , yea = 0 ;
1057
+ zend_long hou , min , sec , mon , day , yea ;
1058
+ zend_bool min_is_null = 1 , sec_is_null = 1 , mon_is_null = 1 , day_is_null = 1 , yea_is_null = 1 ;
1055
1059
timelib_time * now ;
1056
1060
timelib_tzinfo * tzi = NULL ;
1057
1061
zend_long ts , adjust_seconds = 0 ;
@@ -1060,11 +1064,11 @@ PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
1060
1064
ZEND_PARSE_PARAMETERS_START (1 , 6 )
1061
1065
Z_PARAM_LONG (hou )
1062
1066
Z_PARAM_OPTIONAL
1063
- Z_PARAM_LONG (min )
1064
- Z_PARAM_LONG (sec )
1065
- Z_PARAM_LONG (mon )
1066
- Z_PARAM_LONG (day )
1067
- Z_PARAM_LONG (yea )
1067
+ Z_PARAM_LONG_OR_NULL (min , min_is_null )
1068
+ Z_PARAM_LONG_OR_NULL (sec , sec_is_null )
1069
+ Z_PARAM_LONG_OR_NULL (mon , mon_is_null )
1070
+ Z_PARAM_LONG_OR_NULL (day , day_is_null )
1071
+ Z_PARAM_LONG_OR_NULL (yea , yea_is_null )
1068
1072
ZEND_PARSE_PARAMETERS_END ();
1069
1073
1070
1074
/* Initialize structure with current time */
@@ -1077,33 +1081,34 @@ PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
1077
1081
now -> zone_type = TIMELIB_ZONETYPE_ID ;
1078
1082
timelib_unixtime2local (now , (timelib_sll ) php_time ());
1079
1083
}
1080
- /* Fill in the new data */
1081
- switch (ZEND_NUM_ARGS ()) {
1082
- case 6 :
1083
- if (yea >= 0 && yea < 70 ) {
1084
- yea += 2000 ;
1085
- } else if (yea >= 70 && yea <= 100 ) {
1086
- yea += 1900 ;
1087
- }
1088
- now -> y = yea ;
1089
- /* break intentionally missing again */
1090
- case 5 :
1091
- now -> d = day ;
1092
- /* break missing intentionally here too */
1093
- case 4 :
1094
- now -> m = mon ;
1095
- /* and here */
1096
- case 3 :
1097
- now -> s = sec ;
1098
- /* yup, this break isn't here on purpose too */
1099
- case 2 :
1100
- now -> i = min ;
1101
- /* last intentionally missing break */
1102
- case 1 :
1103
- now -> h = hou ;
1104
- break ;
1105
- EMPTY_SWITCH_DEFAULT_CASE ()
1084
+
1085
+ now -> h = hou ;
1086
+
1087
+ if (!min_is_null ) {
1088
+ now -> i = min ;
1089
+ }
1090
+
1091
+ if (!sec_is_null ) {
1092
+ now -> s = sec ;
1093
+ }
1094
+
1095
+ if (!mon_is_null ) {
1096
+ now -> m = mon ;
1106
1097
}
1098
+
1099
+ if (!day_is_null ) {
1100
+ now -> d = day ;
1101
+ }
1102
+
1103
+ if (!yea_is_null ) {
1104
+ if (yea >= 0 && yea < 70 ) {
1105
+ yea += 2000 ;
1106
+ } else if (yea >= 70 && yea <= 100 ) {
1107
+ yea += 1900 ;
1108
+ }
1109
+ now -> y = yea ;
1110
+ }
1111
+
1107
1112
/* Update the timestamp */
1108
1113
if (gmt ) {
1109
1114
timelib_update_ts (now , NULL );
@@ -1163,7 +1168,8 @@ PHP_FUNCTION(checkdate)
1163
1168
PHPAPI void php_strftime (INTERNAL_FUNCTION_PARAMETERS , int gmt )
1164
1169
{
1165
1170
zend_string * format ;
1166
- zend_long timestamp = 0 ;
1171
+ zend_long timestamp ;
1172
+ zend_bool timestamp_is_null = 1 ;
1167
1173
struct tm ta ;
1168
1174
int max_reallocs = 5 ;
1169
1175
size_t buf_len = 256 , real_len ;
@@ -1172,18 +1178,20 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
1172
1178
timelib_time_offset * offset = NULL ;
1173
1179
zend_string * buf ;
1174
1180
1175
- timestamp = (zend_long ) php_time ();
1176
-
1177
1181
ZEND_PARSE_PARAMETERS_START (1 , 2 )
1178
1182
Z_PARAM_STR (format )
1179
1183
Z_PARAM_OPTIONAL
1180
- Z_PARAM_LONG (timestamp )
1184
+ Z_PARAM_LONG_OR_NULL (timestamp , timestamp_is_null )
1181
1185
ZEND_PARSE_PARAMETERS_END ();
1182
1186
1183
1187
if (ZSTR_LEN (format ) == 0 ) {
1184
1188
RETURN_FALSE ;
1185
1189
}
1186
1190
1191
+ if (timestamp_is_null ) {
1192
+ timestamp = (zend_long ) php_time ();
1193
+ }
1194
+
1187
1195
ts = timelib_time_ctor ();
1188
1196
if (gmt ) {
1189
1197
tzi = NULL ;
@@ -1286,17 +1294,18 @@ PHP_FUNCTION(time)
1286
1294
PHP_FUNCTION (localtime )
1287
1295
{
1288
1296
zend_long timestamp ;
1297
+ zend_bool timestamp_is_null = 1 ;
1289
1298
zend_bool associative = 0 ;
1290
1299
timelib_tzinfo * tzi ;
1291
1300
timelib_time * ts ;
1292
1301
1293
1302
ZEND_PARSE_PARAMETERS_START (0 , 2 )
1294
1303
Z_PARAM_OPTIONAL
1295
- Z_PARAM_LONG (timestamp )
1304
+ Z_PARAM_LONG_OR_NULL (timestamp , timestamp_is_null )
1296
1305
Z_PARAM_BOOL (associative )
1297
1306
ZEND_PARSE_PARAMETERS_END ();
1298
1307
1299
- if (ZEND_NUM_ARGS () == 0 ) {
1308
+ if (timestamp_is_null ) {
1300
1309
timestamp = (zend_long ) php_time ();
1301
1310
}
1302
1311
@@ -1339,15 +1348,16 @@ PHP_FUNCTION(localtime)
1339
1348
PHP_FUNCTION (getdate )
1340
1349
{
1341
1350
zend_long timestamp ;
1351
+ zend_bool timestamp_is_null = 1 ;
1342
1352
timelib_tzinfo * tzi ;
1343
1353
timelib_time * ts ;
1344
1354
1345
1355
ZEND_PARSE_PARAMETERS_START (0 , 1 )
1346
1356
Z_PARAM_OPTIONAL
1347
- Z_PARAM_LONG (timestamp )
1357
+ Z_PARAM_LONG_OR_NULL (timestamp , timestamp_is_null )
1348
1358
ZEND_PARSE_PARAMETERS_END ();
1349
1359
1350
- if (ZEND_NUM_ARGS () == 0 ) {
1360
+ if (timestamp_is_null ) {
1351
1361
timestamp = (zend_long ) php_time ();
1352
1362
}
1353
1363
@@ -4511,10 +4521,11 @@ PHP_FUNCTION(date_default_timezone_get)
4511
4521
*/
4512
4522
static void php_do_date_sunrise_sunset (INTERNAL_FUNCTION_PARAMETERS , int calc_sunset )
4513
4523
{
4514
- double latitude = 0.0 , longitude = 0.0 , zenith = 0.0 , gmt_offset = 0 , altitude ;
4524
+ double latitude , longitude , zenith , gmt_offset , altitude ;
4525
+ zend_bool latitude_is_null = 1 , longitude_is_null = 1 , zenith_is_null = 1 , gmt_offset_is_null = 1 ;
4515
4526
double h_rise , h_set , N ;
4516
4527
timelib_sll rise , set , transit ;
4517
- zend_long time , retformat = 0 ;
4528
+ zend_long time , retformat = SUNFUNCS_RET_STRING ;
4518
4529
int rs ;
4519
4530
timelib_time * t ;
4520
4531
timelib_tzinfo * tzi ;
@@ -4524,33 +4535,28 @@ static void php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAMETERS, int calc_su
4524
4535
Z_PARAM_LONG (time )
4525
4536
Z_PARAM_OPTIONAL
4526
4537
Z_PARAM_LONG (retformat )
4527
- Z_PARAM_DOUBLE (latitude )
4528
- Z_PARAM_DOUBLE (longitude )
4529
- Z_PARAM_DOUBLE (zenith )
4530
- Z_PARAM_DOUBLE (gmt_offset )
4538
+ Z_PARAM_DOUBLE_OR_NULL (latitude , latitude_is_null )
4539
+ Z_PARAM_DOUBLE_OR_NULL (longitude , longitude_is_null )
4540
+ Z_PARAM_DOUBLE_OR_NULL (zenith , zenith_is_null )
4541
+ Z_PARAM_DOUBLE_OR_NULL (gmt_offset , gmt_offset_is_null )
4531
4542
ZEND_PARSE_PARAMETERS_END ();
4532
4543
4533
- switch (ZEND_NUM_ARGS ()) {
4534
- case 1 :
4535
- retformat = SUNFUNCS_RET_STRING ;
4536
- case 2 :
4537
- latitude = INI_FLT ("date.default_latitude" );
4538
- case 3 :
4539
- longitude = INI_FLT ("date.default_longitude" );
4540
- case 4 :
4541
- if (calc_sunset ) {
4542
- zenith = INI_FLT ("date.sunset_zenith" );
4543
- } else {
4544
- zenith = INI_FLT ("date.sunrise_zenith" );
4545
- }
4546
- case 5 :
4547
- case 6 :
4548
- break ;
4549
- default :
4550
- php_error_docref (NULL , E_WARNING , "Invalid format" );
4551
- RETURN_FALSE ;
4552
- break ;
4544
+ if (latitude_is_null ) {
4545
+ latitude = INI_FLT ("date.default_latitude" );
4546
+ }
4547
+
4548
+ if (longitude_is_null ) {
4549
+ latitude = INI_FLT ("date.default_longitude" );
4550
+ }
4551
+
4552
+ if (zenith_is_null ) {
4553
+ if (calc_sunset ) {
4554
+ zenith = INI_FLT ("date.sunset_zenith" );
4555
+ } else {
4556
+ zenith = INI_FLT ("date.sunrise_zenith" );
4557
+ }
4553
4558
}
4559
+
4554
4560
if (retformat != SUNFUNCS_RET_TIMESTAMP &&
4555
4561
retformat != SUNFUNCS_RET_STRING &&
4556
4562
retformat != SUNFUNCS_RET_DOUBLE )
@@ -4566,7 +4572,7 @@ static void php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAMETERS, int calc_su
4566
4572
t -> tz_info = tzi ;
4567
4573
t -> zone_type = TIMELIB_ZONETYPE_ID ;
4568
4574
4569
- if (ZEND_NUM_ARGS () <= 5 ) {
4575
+ if (gmt_offset_is_null ) {
4570
4576
gmt_offset = timelib_get_current_offset (t ) / 3600 ;
4571
4577
}
4572
4578
0 commit comments