Skip to content

Commit 658c599

Browse files
committed
Merge remote-tracking branch 'hnw/pr/44' into fixes
hnw#44 * hnw/pr/44: Support strict_types=1 for overridden functions Fixes hnw#43
2 parents 14739d9 + aa0e74c commit 658c599

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

tests/issue_043.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Check for issue #43 (Overridden functions ignore declare(strict_types=1))
3+
--SKIPIF--
4+
<?php
5+
$required_version = "7.0";
6+
$required_func = array("strtotime");
7+
include(__DIR__."/tests-skipcheck.inc.php");
8+
--INI--
9+
date.timezone=GMT
10+
timecop.func_override=1
11+
--FILE--
12+
<?php
13+
declare(strict_types=1);
14+
15+
try {
16+
strtotime(null);
17+
echo "No error thrown!";
18+
} catch (TypeError $e) {
19+
echo $e->getMessage();
20+
}
21+
--EXPECT--
22+
timecop_strtotime() expects parameter 1 to be string, null given

timecop_php7.c

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,17 @@ PHP_FUNCTION(timecop_time)
10951095
Get UNIX timestamp for a date */
10961096
PHP_FUNCTION(timecop_mktime)
10971097
{
1098+
zend_long hou = 0, min = 0, sec = 0, mon = 0, day = 0, yea = 0;
1099+
ZEND_PARSE_PARAMETERS_START(0, 6)
1100+
Z_PARAM_OPTIONAL
1101+
Z_PARAM_LONG(hou)
1102+
Z_PARAM_LONG(min)
1103+
Z_PARAM_LONG(sec)
1104+
Z_PARAM_LONG(mon)
1105+
Z_PARAM_LONG(day)
1106+
Z_PARAM_LONG(yea)
1107+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
1108+
10981109
TIMECOP_CALL_MKTIME("mktime", "date");
10991110
}
11001111
/* }}} */
@@ -1103,6 +1114,17 @@ PHP_FUNCTION(timecop_mktime)
11031114
Get UNIX timestamp for a GMT date */
11041115
PHP_FUNCTION(timecop_gmmktime)
11051116
{
1117+
zend_long hou = 0, min = 0, sec = 0, mon = 0, day = 0, yea = 0;
1118+
ZEND_PARSE_PARAMETERS_START(0, 6)
1119+
Z_PARAM_OPTIONAL
1120+
Z_PARAM_LONG(hou)
1121+
Z_PARAM_LONG(min)
1122+
Z_PARAM_LONG(sec)
1123+
Z_PARAM_LONG(mon)
1124+
Z_PARAM_LONG(day)
1125+
Z_PARAM_LONG(yea)
1126+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
1127+
11061128
TIMECOP_CALL_MKTIME("gmmktime", "gmdate");
11071129
}
11081130
/* }}} */
@@ -1111,6 +1133,14 @@ PHP_FUNCTION(timecop_gmmktime)
11111133
Format a local date/time */
11121134
PHP_FUNCTION(timecop_date)
11131135
{
1136+
zend_string *format;
1137+
zend_long ts;
1138+
ZEND_PARSE_PARAMETERS_START(1, 2)
1139+
Z_PARAM_STR(format)
1140+
Z_PARAM_OPTIONAL
1141+
Z_PARAM_LONG(ts)
1142+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
1143+
11141144
TIMECOP_CALL_FUNCTION("date", 1);
11151145
}
11161146
/* }}} */
@@ -1119,6 +1149,14 @@ PHP_FUNCTION(timecop_date)
11191149
Format a GMT date/time */
11201150
PHP_FUNCTION(timecop_gmdate)
11211151
{
1152+
zend_string *format;
1153+
zend_long ts;
1154+
ZEND_PARSE_PARAMETERS_START(1, 2)
1155+
Z_PARAM_STR(format)
1156+
Z_PARAM_OPTIONAL
1157+
Z_PARAM_LONG(ts)
1158+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
1159+
11221160
TIMECOP_CALL_FUNCTION("gmdate", 1);
11231161
}
11241162
/* }}} */
@@ -1127,6 +1165,14 @@ PHP_FUNCTION(timecop_gmdate)
11271165
Format a local time/date as integer */
11281166
PHP_FUNCTION(timecop_idate)
11291167
{
1168+
zend_string *format;
1169+
zend_long ts;
1170+
ZEND_PARSE_PARAMETERS_START(1, 2)
1171+
Z_PARAM_STR(format)
1172+
Z_PARAM_OPTIONAL
1173+
Z_PARAM_LONG(ts)
1174+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
1175+
11301176
TIMECOP_CALL_FUNCTION("idate", 1);
11311177
}
11321178
/* }}} */
@@ -1135,6 +1181,12 @@ PHP_FUNCTION(timecop_idate)
11351181
Get date/time information */
11361182
PHP_FUNCTION(timecop_getdate)
11371183
{
1184+
zend_long ts;
1185+
ZEND_PARSE_PARAMETERS_START(0, 1)
1186+
Z_PARAM_OPTIONAL
1187+
Z_PARAM_LONG(ts)
1188+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
1189+
11381190
TIMECOP_CALL_FUNCTION("getdate", 0);
11391191
}
11401192
/* }}} */
@@ -1144,6 +1196,14 @@ PHP_FUNCTION(timecop_getdate)
11441196
the associative_array argument is set to 1 other wise it is a regular array */
11451197
PHP_FUNCTION(timecop_localtime)
11461198
{
1199+
zend_long timestamp;
1200+
zend_bool associative;
1201+
ZEND_PARSE_PARAMETERS_START(0, 2)
1202+
Z_PARAM_OPTIONAL
1203+
Z_PARAM_LONG(timestamp)
1204+
Z_PARAM_BOOL(associative)
1205+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
1206+
11471207
TIMECOP_CALL_FUNCTION("localtime", 0);
11481208
}
11491209
/* }}} */
@@ -1152,6 +1212,14 @@ PHP_FUNCTION(timecop_localtime)
11521212
Convert string representation of date and time to a timestamp */
11531213
PHP_FUNCTION(timecop_strtotime)
11541214
{
1215+
zend_string *times;
1216+
zend_long preset_ts;
1217+
ZEND_PARSE_PARAMETERS_START(1, 2)
1218+
Z_PARAM_STR(times)
1219+
Z_PARAM_OPTIONAL
1220+
Z_PARAM_LONG(preset_ts)
1221+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
1222+
11551223
TIMECOP_CALL_FUNCTION("strtotime", 1);
11561224
}
11571225
/* }}} */
@@ -1160,6 +1228,14 @@ PHP_FUNCTION(timecop_strtotime)
11601228
Format a local time/date according to locale settings */
11611229
PHP_FUNCTION(timecop_strftime)
11621230
{
1231+
zend_string *format;
1232+
zend_long timestamp;
1233+
ZEND_PARSE_PARAMETERS_START(1, 2)
1234+
Z_PARAM_STR(format)
1235+
Z_PARAM_OPTIONAL
1236+
Z_PARAM_LONG(timestamp)
1237+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
1238+
11631239
TIMECOP_CALL_FUNCTION("strftime", 1);
11641240
}
11651241
/* }}} */
@@ -1168,6 +1244,14 @@ PHP_FUNCTION(timecop_strftime)
11681244
Format a GMT/UCT time/date according to locale settings */
11691245
PHP_FUNCTION(timecop_gmstrftime)
11701246
{
1247+
zend_string *format;
1248+
zend_long timestamp = 0;
1249+
ZEND_PARSE_PARAMETERS_START(1, 2)
1250+
Z_PARAM_STR(format)
1251+
Z_PARAM_OPTIONAL
1252+
Z_PARAM_LONG(timestamp)
1253+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
1254+
11711255
TIMECOP_CALL_FUNCTION("gmstrftime", 1);
11721256
}
11731257
/* }}} */

0 commit comments

Comments
 (0)