Skip to content

Add some ValueErrors to ext/date #5613

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

Closed
wants to merge 11 commits into from
Prev Previous commit
Next Next commit
Revert idate() changes
  • Loading branch information
Girgias committed Sep 15, 2020
commit 9362d5a81287308030be53fce0a8db73fc331fe6
8 changes: 4 additions & 4 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,8 @@ PHP_FUNCTION(idate)
ZEND_PARSE_PARAMETERS_END();

if (ZSTR_LEN(format) != 1) {
zend_argument_value_error(1, "must be one character");
RETURN_THROWS();
php_error_docref(NULL, E_WARNING, "idate format is one char");
RETURN_FALSE;
}

if (ts_is_null) {
Expand All @@ -961,8 +961,8 @@ PHP_FUNCTION(idate)

ret = php_idate(ZSTR_VAL(format)[0], ts, 0);
if (ret == -1) {
zend_argument_value_error(1, "must be a valid date format token");
RETURN_THROWS();
php_error_docref(NULL, E_WARNING, "Unrecognized date format token");
RETURN_FALSE;
}
RETURN_LONG(ret);
}
Expand Down
2 changes: 1 addition & 1 deletion ext/date/php_date.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function strtotime(string $datetime, ?int $baseTimestamp = null): int|false {}

function date(string $format, ?int $timestamp = null): string {}

function idate(string $format, ?int $timestamp = null): int {}
function idate(string $format, ?int $timestamp = null): int|false {}

function gmdate(string $format, ?int $timestamp = null): string {}

Expand Down
4 changes: 2 additions & 2 deletions ext/date/php_date_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: eae561b0424a4837d35239b66be8c545d7ac2b04 */
* Stub hash: cb1532309655d85eb2644cdcfbf23063dfa1ddaf */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_strtotime, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, datetime, IS_STRING, 0)
Expand All @@ -11,7 +11,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_date, 0, 1, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timestamp, IS_LONG, 1, "null")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_idate, 0, 1, IS_LONG, 0)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_idate, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, format, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timestamp, IS_LONG, 1, "null")
ZEND_END_ARG_INFO()
Expand Down
53 changes: 20 additions & 33 deletions ext/date/tests/005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,29 @@ date_default_timezone_set('UTC');

$t = mktime(0,0,0, 6, 27, 2006);

try {
var_dump(idate(1,1));
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
try {
var_dump(idate(""));
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
try {
var_dump(idate(0));
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}

var_dump(idate(1,1));
var_dump(idate(""));
var_dump(idate(0));
var_dump(idate("B", $t));

try {
var_dump(idate("[", $t));
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
try {
var_dump(idate("'"));
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
var_dump(idate("[", $t));
var_dump(idate("'"));

echo "Done\n";
?>
--EXPECT--
idate(): Argument #1 ($format) must be a valid date format token
idate(): Argument #1 ($format) must be one character
idate(): Argument #1 ($format) must be a valid date format token
--EXPECTF--
Warning: idate(): Unrecognized date format token in %s on line %d
bool(false)

Warning: idate(): idate format is one char in %s on line %d
bool(false)

Warning: idate(): Unrecognized date format token in %s on line %d
bool(false)
int(41)
idate(): Argument #1 ($format) must be a valid date format token
idate(): Argument #1 ($format) must be a valid date format token

Warning: idate(): Unrecognized date format token in %s on line %d
bool(false)

Warning: idate(): Unrecognized date format token in %s on line %d
bool(false)
Done