derick Thu Jan 17 20:35:02 2008 UTC Added files: (Branch: PHP_5_3) /php-src/ext/date/tests bug43808.phpt
Modified files: /php-src NEWS /php-src/ext/date php_date.c Log: - MFH: Fixed bug #43808 (date_create never fails (even when it should)). http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.74&r2=1.2027.2.547.2.965.2.75&diff_format=u Index: php-src/NEWS diff -u php-src/NEWS:1.2027.2.547.2.965.2.74 php-src/NEWS:1.2027.2.547.2.965.2.75 --- php-src/NEWS:1.2027.2.547.2.965.2.74 Thu Jan 17 19:58:59 2008 +++ php-src/NEWS Thu Jan 17 20:35:01 2008 @@ -77,6 +77,7 @@ - Fixed possible crash in ext/soap because of uninitialized value. (Zdash Urf) +- Fixed bug #43808 (date_create never fails (even when it should)). (Derick) - Fixed bug #43527 (DateTime created from a timestamp reports environment timezone). (Derick) - Fixed bug #43003 (Invalid timezone reported for DateTime objects constructed http://cvs.php.net/viewvc.cgi/php-src/ext/date/php_date.c?r1=1.43.2.45.2.51.2.10&r2=1.43.2.45.2.51.2.11&diff_format=u Index: php-src/ext/date/php_date.c diff -u php-src/ext/date/php_date.c:1.43.2.45.2.51.2.10 php-src/ext/date/php_date.c:1.43.2.45.2.51.2.11 --- php-src/ext/date/php_date.c:1.43.2.45.2.51.2.10 Thu Jan 17 19:59:00 2008 +++ php-src/ext/date/php_date.c Thu Jan 17 20:35:01 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_date.c,v 1.43.2.45.2.51.2.10 2008/01/17 19:59:00 derick Exp $ */ +/* $Id: php_date.c,v 1.43.2.45.2.51.2.11 2008/01/17 20:35:01 derick Exp $ */ #include "php.h" #include "php_streams.h" @@ -1702,7 +1702,7 @@ DATEG(last_errors) = last_errors; } -static void date_initialize(php_date_obj *dateobj, /*const*/ char *time_str, int time_str_len, char *format, zval *timezone_object TSRMLS_DC) +static int date_initialize(php_date_obj *dateobj, /*const*/ char *time_str, int time_str_len, char *format, zval *timezone_object, int ctor TSRMLS_DC) { timelib_time *now; timelib_tzinfo *tzi; @@ -1726,6 +1726,16 @@ // update last errors and warnings update_errors_warnings(err TSRMLS_CC); + + if (ctor && err && err->error_count) { + /* spit out the first library error message, at least */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse time string (%s) at position %d (%c): %s", time_str, + err->error_messages[0].position, err->error_messages[0].character, err->error_messages[0].message); + } + if (err && err->error_count) { + return 0; + } + if (timezone_object) { php_timezone_obj *tzobj; @@ -1780,7 +1790,9 @@ if (free_tzi) { timelib_tzinfo_dtor(tzi); } - timelib_time_dtor(now); + timelib_time_dtor(now); + + return 1; } /* {{{ proto DateTime date_create([string time[, DateTimeZone object]]) @@ -1797,7 +1809,9 @@ } date_instantiate(date_ce_date, return_value TSRMLS_CC); - date_initialize(zend_object_store_get_object(return_value TSRMLS_CC), time_str, time_str_len, NULL, timezone_object TSRMLS_CC); + if (!date_initialize(zend_object_store_get_object(return_value TSRMLS_CC), time_str, time_str_len, NULL, timezone_object, 0 TSRMLS_CC)) { + RETURN_FALSE; + } } /* }}} */ @@ -1815,7 +1829,9 @@ } date_instantiate(date_ce_date, return_value TSRMLS_CC); - date_initialize(zend_object_store_get_object(return_value TSRMLS_CC), time_str, time_str_len, format_str, timezone_object TSRMLS_CC); + if (!date_initialize(zend_object_store_get_object(return_value TSRMLS_CC), time_str, time_str_len, format_str, timezone_object, 0 TSRMLS_CC)) { + RETURN_FALSE; + } } /* }}} */ @@ -1830,7 +1846,7 @@ php_set_error_handling(EH_THROW, NULL TSRMLS_CC); if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sO", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) { - date_initialize(zend_object_store_get_object(getThis() TSRMLS_CC), time_str, time_str_len, NULL, timezone_object TSRMLS_CC); + date_initialize(zend_object_store_get_object(getThis() TSRMLS_CC), time_str, time_str_len, NULL, timezone_object, 1 TSRMLS_CC); } php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); } http://cvs.php.net/viewvc.cgi/php-src/ext/date/tests/bug43808.phpt?view=markup&rev=1.1 Index: php-src/ext/date/tests/bug43808.phpt +++ php-src/ext/date/tests/bug43808.phpt --TEST-- Bug #43808 (date_create never fails (even when it should)) --FILE-- <?php $date = date_create('asdfasdf'); if ($date instanceof DateTime) { echo "this is wrong, should be bool"; } var_dump( $date ); var_dump( DateTime::getLastErrors() ); var_dump( date_get_last_errors() ); ?> --EXPECT-- bool(false) array(4) { ["warning_count"]=> int(1) ["warnings"]=> array(1) { [6]=> string(29) "Double timezone specification" } ["error_count"]=> int(1) ["errors"]=> array(1) { [0]=> string(47) "The timezone could not be found in the database" } } array(4) { ["warning_count"]=> int(1) ["warnings"]=> array(1) { [6]=> string(29) "Double timezone specification" } ["error_count"]=> int(1) ["errors"]=> array(1) { [0]=> string(47) "The timezone could not be found in the database" } } --UEXPECT-- bool(false) array(4) { [u"warning_count"]=> int(1) [u"warnings"]=> array(1) { [6]=> string(29) "Double timezone specification" } [u"error_count"]=> int(1) [u"errors"]=> array(1) { [0]=> string(47) "The timezone could not be found in the database" } } array(4) { [u"warning_count"]=> int(1) [u"warnings"]=> array(1) { [6]=> string(29) "Double timezone specification" } [u"error_count"]=> int(1) [u"errors"]=> array(1) { [0]=> string(47) "The timezone could not be found in the database" } } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php