summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMáté Kocsis <kocsismate@woohoolabs.com>2020-05-01 20:49:55 +0200
committerMáté Kocsis <kocsismate@woohoolabs.com>2020-05-02 11:05:27 +0200
commit089d8cb03ccf51523c4c080e68d2e64848b6e2cc (patch)
tree5c8c362647878e76855de6025f883656c6f62217
parent8a41c9e025b003ff26b9bf76728f3cd054474e08 (diff)
downloadphp-git-089d8cb03ccf51523c4c080e68d2e64848b6e2cc.tar.gz
Convert UNKNOWN default values to null in ext/calendar
-rw-r--r--ext/calendar/cal_unix.c7
-rw-r--r--ext/calendar/calendar.c4
-rw-r--r--ext/calendar/calendar.stub.php8
-rw-r--r--ext/calendar/calendar_arginfo.h6
-rw-r--r--ext/calendar/easter.c14
5 files changed, 19 insertions, 20 deletions
diff --git a/ext/calendar/cal_unix.c b/ext/calendar/cal_unix.c
index 4738772649..cfcc62f11b 100644
--- a/ext/calendar/cal_unix.c
+++ b/ext/calendar/cal_unix.c
@@ -25,14 +25,15 @@
Convert UNIX timestamp to Julian Day */
PHP_FUNCTION(unixtojd)
{
- time_t ts = 0;
+ time_t ts;
+ zend_bool ts_is_null = 1;
struct tm *ta, tmbuf;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &ts) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &ts, &ts_is_null) == FAILURE) {
RETURN_THROWS();
}
- if (!ts) {
+ if (ts_is_null) {
ts = time(NULL);
} else if (ts < 0) {
zend_argument_value_error(1, "must be greater than or equal to 0");
diff --git a/ext/calendar/calendar.c b/ext/calendar/calendar.c
index 2853e72775..fd8b107156 100644
--- a/ext/calendar/calendar.c
+++ b/ext/calendar/calendar.c
@@ -192,14 +192,12 @@ PHP_FUNCTION(cal_info)
return;
}
-
- if (cal != -1 && (cal < 0 || cal >= CAL_NUM_CALS)) {
+ if (cal < 0 || cal >= CAL_NUM_CALS) {
zend_argument_value_error(1, "must be a valid calendar ID");
RETURN_THROWS();
}
_php_cal_info(cal, return_value);
-
}
/* }}} */
diff --git a/ext/calendar/calendar.stub.php b/ext/calendar/calendar.stub.php
index 1c2db30ce4..baa2075bee 100644
--- a/ext/calendar/calendar.stub.php
+++ b/ext/calendar/calendar.stub.php
@@ -6,13 +6,13 @@ function cal_days_in_month(int $calendar, int $month, int $year): int {}
function cal_from_jd(int $jd, int $calendar): array {}
-function cal_info(?int $calendar = UNKNOWN): array {}
+function cal_info(int $calendar = -1): array {}
function cal_to_jd(int $calendar, int $month, int $day, int $year): int {}
-function easter_date(int $year = UNKNOWN, int $method = CAL_EASTER_DEFAULT): int {}
+function easter_date(?int $year = null, int $method = CAL_EASTER_DEFAULT): int {}
-function easter_days(int $year = UNKNOWN, int $method = CAL_EASTER_DEFAULT): int {}
+function easter_days(?int $year = null, int $method = CAL_EASTER_DEFAULT): int {}
function frenchtojd(int $month, int $day, int $year): int {}
@@ -36,4 +36,4 @@ function jewishtojd(int $month, int $day, int $year): int {}
function juliantojd(int $month, int $day, int $year): int {}
-function unixtojd(int $timestamp = UNKNOWN): int|false {}
+function unixtojd(?int $timestamp = null): int|false {}
diff --git a/ext/calendar/calendar_arginfo.h b/ext/calendar/calendar_arginfo.h
index 45abb0b0b2..620f3daec3 100644
--- a/ext/calendar/calendar_arginfo.h
+++ b/ext/calendar/calendar_arginfo.h
@@ -12,7 +12,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_cal_from_jd, 0, 2, IS_ARRAY, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_cal_info, 0, 0, IS_ARRAY, 0)
- ZEND_ARG_TYPE_INFO(0, calendar, IS_LONG, 1)
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, calendar, IS_LONG, 0, "-1")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_cal_to_jd, 0, 4, IS_LONG, 0)
@@ -23,7 +23,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_cal_to_jd, 0, 4, IS_LONG, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_easter_date, 0, 0, IS_LONG, 0)
- ZEND_ARG_TYPE_INFO(0, year, IS_LONG, 0)
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, year, IS_LONG, 1, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, method, IS_LONG, 0, "CAL_EASTER_DEFAULT")
ZEND_END_ARG_INFO()
@@ -70,7 +70,7 @@ ZEND_END_ARG_INFO()
#define arginfo_juliantojd arginfo_frenchtojd
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_unixtojd, 0, 0, MAY_BE_LONG|MAY_BE_FALSE)
- ZEND_ARG_TYPE_INFO(0, timestamp, IS_LONG, 0)
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timestamp, IS_LONG, 1, "null")
ZEND_END_ARG_INFO()
diff --git a/ext/calendar/easter.c b/ext/calendar/easter.c
index 7f26de0c00..05f54084b4 100644
--- a/ext/calendar/easter.c
+++ b/ext/calendar/easter.c
@@ -23,15 +23,20 @@
static void _cal_easter(INTERNAL_FUNCTION_PARAMETERS, zend_long gm)
{
-
/* based on code by Simon Kershaw, <webmaster@ely.anglican.org> */
struct tm te;
zend_long year, golden, solar, lunar, pfm, dom, tmp, easter, result;
zend_long method = CAL_EASTER_DEFAULT;
+ zend_bool year_is_null = 1;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(),
+ "|l!l", &year, &year_is_null, &method) == FAILURE) {
+ RETURN_THROWS();
+ }
/* Default to the current year if year parameter is not given */
- {
+ if (year_is_null) {
time_t a;
struct tm b, *res;
time(&a);
@@ -43,11 +48,6 @@ static void _cal_easter(INTERNAL_FUNCTION_PARAMETERS, zend_long gm)
}
}
- if (zend_parse_parameters(ZEND_NUM_ARGS(),
- "|ll", &year, &method) == FAILURE) {
- RETURN_THROWS();
- }
-
if (gm && (year<1970 || year>2037)) { /* out of range for timestamps */
zend_argument_value_error(1, "must be between 1970 and 2037 (inclusive)");
RETURN_THROWS();