1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
From aa0e74ca7f9fdff5fb25dc990a72005a8bfc018e Mon Sep 17 00:00:00 2001
From: Ben Allison <ben1120@gmail.com>
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--
+<?php
+$required_version = "7.0";
+$required_func = array("strtotime");
+include(__DIR__."/tests-skipcheck.inc.php");
+--INI--
+date.timezone=GMT
+timecop.func_override=1
+--FILE--
+<?php
+declare(strict_types=1);
+
+try {
+ strtotime(null);
+ echo "No error thrown!";
+} catch (TypeError $e) {
+ echo $e->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);
}
/* }}} */
|