diff options
| author | Michael Wallner <mike@php.net> | 2006-08-01 15:55:03 +0000 |
|---|---|---|
| committer | Michael Wallner <mike@php.net> | 2006-08-01 15:55:03 +0000 |
| commit | 68613beb3ec3c523c8db4d371af730a61c6082da (patch) | |
| tree | af68fda7152835151d7f0bff9e3b2186e89cd440 | |
| parent | 2b5a53d6b6a9d452a9370fd7c6308a5d083087f7 (diff) | |
| download | php-git-68613beb3ec3c523c8db4d371af730a61c6082da.tar.gz | |
MFH:
- fix leaks on multiple calls to DateTime::__construct()
- throw exception on unparseable time strings in DateTime::__construct()
| -rw-r--r-- | ext/date/php_date.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/ext/date/php_date.c b/ext/date/php_date.c index ca8d3a4ed4..5aa3b8766e 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -1544,9 +1544,22 @@ static void date_initialize(php_date_obj *dateobj, /*const*/ char *time_str, int { timelib_time *now; timelib_tzinfo *tzi; + timelib_error_container *err = NULL; int free_tzi = 0; - dateobj->time = timelib_strtotime(time_str_len ? time_str : "now", time_str_len ? time_str_len : sizeof("now") -1, NULL, DATE_TIMEZONEDB); + if (dateobj->time) { + if (dateobj->time->tz_info) { + timelib_tzinfo_dtor(dateobj->time->tz_info); + } + timelib_time_dtor(dateobj->time); + } + dateobj->time = timelib_strtotime(time_str_len ? time_str : "now", time_str_len ? time_str_len : sizeof("now") -1, &err, DATE_TIMEZONEDB); + if (err) { + if (err->error_count) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse time string (%s)", time_str); + } + timelib_error_container_dtor(err); + } if (timezone_object) { php_timezone_obj *tzobj; @@ -1599,8 +1612,9 @@ PHP_METHOD(DateTime, __construct) int time_str_len = 0; if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sO", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) { - /* TODO: throw Exception on unparseable dates */ + php_set_error_handling(EH_THROW, NULL TSRMLS_CC); date_initialize(zend_object_store_get_object(getThis() TSRMLS_CC), time_str, time_str_len, timezone_object TSRMLS_CC); + php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); } } |
