Skip to content

Commit aa0e74c

Browse files
committed
Support strict_types=1 for overridden functions
Fixes hnw#43
1 parent cccc7b4 commit aa0e74c

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
@@ -1088,6 +1088,17 @@ PHP_FUNCTION(timecop_time)
10881088
Get UNIX timestamp for a date */
10891089
PHP_FUNCTION(timecop_mktime)
10901090
{
1091+
zend_long hou = 0, min = 0, sec = 0, mon = 0, day = 0, yea = 0;
1092+
ZEND_PARSE_PARAMETERS_START(0, 6)
1093+
Z_PARAM_OPTIONAL
1094+
Z_PARAM_LONG(hou)
1095+
Z_PARAM_LONG(min)
1096+
Z_PARAM_LONG(sec)
1097+
Z_PARAM_LONG(mon)
1098+
Z_PARAM_LONG(day)
1099+
Z_PARAM_LONG(yea)
1100+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
1101+
10911102
TIMECOP_CALL_MKTIME("mktime", "date");
10921103
}
10931104
/* }}} */
@@ -1096,6 +1107,17 @@ PHP_FUNCTION(timecop_mktime)
10961107
Get UNIX timestamp for a GMT date */
10971108
PHP_FUNCTION(timecop_gmmktime)
10981109
{
1110+
zend_long hou = 0, min = 0, sec = 0, mon = 0, day = 0, yea = 0;
1111+
ZEND_PARSE_PARAMETERS_START(0, 6)
1112+
Z_PARAM_OPTIONAL
1113+
Z_PARAM_LONG(hou)
1114+
Z_PARAM_LONG(min)
1115+
Z_PARAM_LONG(sec)
1116+
Z_PARAM_LONG(mon)
1117+
Z_PARAM_LONG(day)
1118+
Z_PARAM_LONG(yea)
1119+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
1120+
10991121
TIMECOP_CALL_MKTIME("gmmktime", "gmdate");
11001122
}
11011123
/* }}} */
@@ -1104,6 +1126,14 @@ PHP_FUNCTION(timecop_gmmktime)
11041126
Format a local date/time */
11051127
PHP_FUNCTION(timecop_date)
11061128
{
1129+
zend_string *format;
1130+
zend_long ts;
1131+
ZEND_PARSE_PARAMETERS_START(1, 2)
1132+
Z_PARAM_STR(format)
1133+
Z_PARAM_OPTIONAL
1134+
Z_PARAM_LONG(ts)
1135+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
1136+
11071137
TIMECOP_CALL_FUNCTION("date", 1);
11081138
}
11091139
/* }}} */
@@ -1112,6 +1142,14 @@ PHP_FUNCTION(timecop_date)
11121142
Format a GMT date/time */
11131143
PHP_FUNCTION(timecop_gmdate)
11141144
{
1145+
zend_string *format;
1146+
zend_long ts;
1147+
ZEND_PARSE_PARAMETERS_START(1, 2)
1148+
Z_PARAM_STR(format)
1149+
Z_PARAM_OPTIONAL
1150+
Z_PARAM_LONG(ts)
1151+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
1152+
11151153
TIMECOP_CALL_FUNCTION("gmdate", 1);
11161154
}
11171155
/* }}} */
@@ -1120,6 +1158,14 @@ PHP_FUNCTION(timecop_gmdate)
11201158
Format a local time/date as integer */
11211159
PHP_FUNCTION(timecop_idate)
11221160
{
1161+
zend_string *format;
1162+
zend_long ts;
1163+
ZEND_PARSE_PARAMETERS_START(1, 2)
1164+
Z_PARAM_STR(format)
1165+
Z_PARAM_OPTIONAL
1166+
Z_PARAM_LONG(ts)
1167+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
1168+
11231169
TIMECOP_CALL_FUNCTION("idate", 1);
11241170
}
11251171
/* }}} */
@@ -1128,6 +1174,12 @@ PHP_FUNCTION(timecop_idate)
11281174
Get date/time information */
11291175
PHP_FUNCTION(timecop_getdate)
11301176
{
1177+
zend_long ts;
1178+
ZEND_PARSE_PARAMETERS_START(0, 1)
1179+
Z_PARAM_OPTIONAL
1180+
Z_PARAM_LONG(ts)
1181+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
1182+
11311183
TIMECOP_CALL_FUNCTION("getdate", 0);
11321184
}
11331185
/* }}} */
@@ -1137,6 +1189,14 @@ PHP_FUNCTION(timecop_getdate)
11371189
the associative_array argument is set to 1 other wise it is a regular array */
11381190
PHP_FUNCTION(timecop_localtime)
11391191
{
1192+
zend_long timestamp;
1193+
zend_bool associative;
1194+
ZEND_PARSE_PARAMETERS_START(0, 2)
1195+
Z_PARAM_OPTIONAL
1196+
Z_PARAM_LONG(timestamp)
1197+
Z_PARAM_BOOL(associative)
1198+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
1199+
11401200
TIMECOP_CALL_FUNCTION("localtime", 0);
11411201
}
11421202
/* }}} */
@@ -1145,6 +1205,14 @@ PHP_FUNCTION(timecop_localtime)
11451205
Convert string representation of date and time to a timestamp */
11461206
PHP_FUNCTION(timecop_strtotime)
11471207
{
1208+
zend_string *times;
1209+
zend_long preset_ts;
1210+
ZEND_PARSE_PARAMETERS_START(1, 2)
1211+
Z_PARAM_STR(times)
1212+
Z_PARAM_OPTIONAL
1213+
Z_PARAM_LONG(preset_ts)
1214+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
1215+
11481216
TIMECOP_CALL_FUNCTION("strtotime", 1);
11491217
}
11501218
/* }}} */
@@ -1153,6 +1221,14 @@ PHP_FUNCTION(timecop_strtotime)
11531221
Format a local time/date according to locale settings */
11541222
PHP_FUNCTION(timecop_strftime)
11551223
{
1224+
zend_string *format;
1225+
zend_long timestamp;
1226+
ZEND_PARSE_PARAMETERS_START(1, 2)
1227+
Z_PARAM_STR(format)
1228+
Z_PARAM_OPTIONAL
1229+
Z_PARAM_LONG(timestamp)
1230+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
1231+
11561232
TIMECOP_CALL_FUNCTION("strftime", 1);
11571233
}
11581234
/* }}} */
@@ -1161,6 +1237,14 @@ PHP_FUNCTION(timecop_strftime)
11611237
Format a GMT/UCT time/date according to locale settings */
11621238
PHP_FUNCTION(timecop_gmstrftime)
11631239
{
1240+
zend_string *format;
1241+
zend_long timestamp = 0;
1242+
ZEND_PARSE_PARAMETERS_START(1, 2)
1243+
Z_PARAM_STR(format)
1244+
Z_PARAM_OPTIONAL
1245+
Z_PARAM_LONG(timestamp)
1246+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
1247+
11641248
TIMECOP_CALL_FUNCTION("gmstrftime", 1);
11651249
}
11661250
/* }}} */

0 commit comments

Comments
 (0)