From aa0e74ca7f9fdff5fb25dc990a72005a8bfc018e Mon Sep 17 00:00:00 2001 From: Ben Allison Date: Mon, 14 Jan 2019 13:03:17 -0800 Subject: [PATCH] Support strict_types=1 for overridden functions Fixes #43 --- tests/issue_043.phpt | 22 ++++++++++++ timecop_php7.c | 84 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 tests/issue_043.phpt diff --git a/tests/issue_043.phpt b/tests/issue_043.phpt new file mode 100644 index 0000000..9e4fa0b --- /dev/null +++ b/tests/issue_043.phpt @@ -0,0 +1,22 @@ +--TEST-- +Check for issue #43 (Overridden functions ignore declare(strict_types=1)) +--SKIPIF-- +getMessage(); +} +--EXPECT-- +timecop_strtotime() expects parameter 1 to be string, null given diff --git a/timecop_php7.c b/timecop_php7.c index 8d7faec..0a0dda7 100644 --- a/timecop_php7.c +++ b/timecop_php7.c @@ -1088,6 +1088,17 @@ PHP_FUNCTION(timecop_time) Get UNIX timestamp for a date */ PHP_FUNCTION(timecop_mktime) { + zend_long hou = 0, min = 0, sec = 0, mon = 0, day = 0, yea = 0; + ZEND_PARSE_PARAMETERS_START(0, 6) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(hou) + Z_PARAM_LONG(min) + Z_PARAM_LONG(sec) + Z_PARAM_LONG(mon) + Z_PARAM_LONG(day) + Z_PARAM_LONG(yea) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); + TIMECOP_CALL_MKTIME("mktime", "date"); } /* }}} */ @@ -1096,6 +1107,17 @@ PHP_FUNCTION(timecop_mktime) Get UNIX timestamp for a GMT date */ PHP_FUNCTION(timecop_gmmktime) { + zend_long hou = 0, min = 0, sec = 0, mon = 0, day = 0, yea = 0; + ZEND_PARSE_PARAMETERS_START(0, 6) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(hou) + Z_PARAM_LONG(min) + Z_PARAM_LONG(sec) + Z_PARAM_LONG(mon) + Z_PARAM_LONG(day) + Z_PARAM_LONG(yea) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); + TIMECOP_CALL_MKTIME("gmmktime", "gmdate"); } /* }}} */ @@ -1104,6 +1126,14 @@ PHP_FUNCTION(timecop_gmmktime) Format a local date/time */ PHP_FUNCTION(timecop_date) { + zend_string *format; + zend_long ts; + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_STR(format) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(ts) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); + TIMECOP_CALL_FUNCTION("date", 1); } /* }}} */ @@ -1112,6 +1142,14 @@ PHP_FUNCTION(timecop_date) Format a GMT date/time */ PHP_FUNCTION(timecop_gmdate) { + zend_string *format; + zend_long ts; + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_STR(format) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(ts) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); + TIMECOP_CALL_FUNCTION("gmdate", 1); } /* }}} */ @@ -1120,6 +1158,14 @@ PHP_FUNCTION(timecop_gmdate) Format a local time/date as integer */ PHP_FUNCTION(timecop_idate) { + zend_string *format; + zend_long ts; + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_STR(format) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(ts) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); + TIMECOP_CALL_FUNCTION("idate", 1); } /* }}} */ @@ -1128,6 +1174,12 @@ PHP_FUNCTION(timecop_idate) Get date/time information */ PHP_FUNCTION(timecop_getdate) { + zend_long ts; + ZEND_PARSE_PARAMETERS_START(0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(ts) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); + TIMECOP_CALL_FUNCTION("getdate", 0); } /* }}} */ @@ -1137,6 +1189,14 @@ PHP_FUNCTION(timecop_getdate) the associative_array argument is set to 1 other wise it is a regular array */ PHP_FUNCTION(timecop_localtime) { + zend_long timestamp; + zend_bool associative; + ZEND_PARSE_PARAMETERS_START(0, 2) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(timestamp) + Z_PARAM_BOOL(associative) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); + TIMECOP_CALL_FUNCTION("localtime", 0); } /* }}} */ @@ -1145,6 +1205,14 @@ PHP_FUNCTION(timecop_localtime) Convert string representation of date and time to a timestamp */ PHP_FUNCTION(timecop_strtotime) { + zend_string *times; + zend_long preset_ts; + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_STR(times) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(preset_ts) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); + TIMECOP_CALL_FUNCTION("strtotime", 1); } /* }}} */ @@ -1153,6 +1221,14 @@ PHP_FUNCTION(timecop_strtotime) Format a local time/date according to locale settings */ PHP_FUNCTION(timecop_strftime) { + zend_string *format; + zend_long timestamp; + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_STR(format) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(timestamp) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); + TIMECOP_CALL_FUNCTION("strftime", 1); } /* }}} */ @@ -1161,6 +1237,14 @@ PHP_FUNCTION(timecop_strftime) Format a GMT/UCT time/date according to locale settings */ PHP_FUNCTION(timecop_gmstrftime) { + zend_string *format; + zend_long timestamp = 0; + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_STR(format) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(timestamp) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); + TIMECOP_CALL_FUNCTION("gmstrftime", 1); } /* }}} */