Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support strict_types=1 for overridden functions #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tests/issue_043.phpt
Original file line number Diff line number Diff line change
@@ -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
84 changes: 84 additions & 0 deletions timecop_php7.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
/* }}} */
Expand All @@ -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");
}
/* }}} */
Expand All @@ -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);
}
/* }}} */
Expand All @@ -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);
}
/* }}} */
Expand All @@ -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);
}
/* }}} */
Expand All @@ -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);
}
/* }}} */
Expand All @@ -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);
}
/* }}} */
Expand All @@ -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);
}
/* }}} */
Expand All @@ -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);
}
/* }}} */
Expand All @@ -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);
}
/* }}} */
Expand Down