Skip to content
Closed
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
10 changes: 9 additions & 1 deletion ext/intl/common/common_date.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,17 @@ U_CFUNC int intl_datetime_decompose(zval *z, double *millis, TimeZone **tz,
return FAILURE;
}

zval_ptr_dtor(&zfuncname);
datetime = Z_PHPDATE_P(z);
if (!datetime->time) {
spprintf(&message, 0, "%s: the %s object is not properly "
"initialized", func, ZSTR_VAL(Z_OBJCE_P(z)->name));
intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR,
message, 1);
efree(message);
return FAILURE;
}
*millis = U_MILLIS_PER_SECOND * (double)Z_LVAL(retval) + (datetime->time->us / 1000);
zval_ptr_dtor(&zfuncname);
}

if (tz) {
Expand Down
33 changes: 33 additions & 0 deletions ext/intl/tests/dateformat_uninitialized_datetime_subclass.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
intl_datetime_decompose() rejects uninitialized DateTime subclass overriding getTimestamp()
--EXTENSIONS--
intl
--FILE--
<?php

class UninitDateTime extends DateTime {
public function __construct() {}
public function getTimestamp(): int {
return 0;
}
}

$dt = new UninitDateTime();

var_dump(IntlDateFormatter::formatObject($dt));
var_dump(intl_get_error_message());

$fmt = new IntlDateFormatter('en_US', IntlDateFormatter::SHORT, IntlDateFormatter::SHORT, 'UTC');
var_dump($fmt->format($dt));
var_dump($fmt->getErrorMessage());

var_dump(MessageFormatter::formatMessage('en_US', '{0,date,short}', [$dt]));
var_dump(intl_get_error_message());
?>
--EXPECTF--
bool(false)
string(%d) "%sthe UninitDateTime object is not properly initialized: U_ILLEGAL_ARGUMENT_ERROR"
bool(false)
string(%d) "%sthe UninitDateTime object is not properly initialized: U_ILLEGAL_ARGUMENT_ERROR"
bool(false)
string(83) "The argument for key '0' cannot be used as a date or time: U_ILLEGAL_ARGUMENT_ERROR"
Loading