@@ -2215,10 +2215,10 @@ PHPAPI int php_date_initialize(php_date_obj *dateobj, const char *time_str, size
2215
2215
/* update last errors and warnings */
2216
2216
update_errors_warnings (err );
2217
2217
2218
-
2218
+ /* If called from a constructor throw an exception */
2219
2219
if ((flags & PHP_DATE_INIT_CTOR ) && err && err -> error_count ) {
2220
2220
/* spit out the first library error message, at least */
2221
- php_error_docref ( NULL , E_WARNING , "Failed to parse time string (%s) at position %d (%c): %s" , time_str ,
2221
+ zend_throw_error ( zend_ce_exception , "Failed to parse time string (%s) at position %d (%c): %s" , time_str ,
2222
2222
err -> error_messages [0 ].position , err -> error_messages [0 ].character , err -> error_messages [0 ].message );
2223
2223
}
2224
2224
if (err && err -> error_count ) {
@@ -2386,17 +2386,14 @@ PHP_METHOD(DateTime, __construct)
2386
2386
zval * timezone_object = NULL ;
2387
2387
char * time_str = NULL ;
2388
2388
size_t time_str_len = 0 ;
2389
- zend_error_handling error_handling ;
2390
2389
2391
2390
ZEND_PARSE_PARAMETERS_START (0 , 2 )
2392
2391
Z_PARAM_OPTIONAL
2393
2392
Z_PARAM_STRING (time_str , time_str_len )
2394
2393
Z_PARAM_OBJECT_OF_CLASS_OR_NULL (timezone_object , date_ce_timezone )
2395
2394
ZEND_PARSE_PARAMETERS_END ();
2396
2395
2397
- zend_replace_error_handling (EH_THROW , NULL , & error_handling );
2398
2396
php_date_initialize (Z_PHPDATE_P (ZEND_THIS ), time_str , time_str_len , NULL , timezone_object , PHP_DATE_INIT_CTOR );
2399
- zend_restore_error_handling (& error_handling );
2400
2397
}
2401
2398
/* }}} */
2402
2399
@@ -2406,17 +2403,14 @@ PHP_METHOD(DateTimeImmutable, __construct)
2406
2403
zval * timezone_object = NULL ;
2407
2404
char * time_str = NULL ;
2408
2405
size_t time_str_len = 0 ;
2409
- zend_error_handling error_handling ;
2410
2406
2411
2407
ZEND_PARSE_PARAMETERS_START (0 , 2 )
2412
2408
Z_PARAM_OPTIONAL
2413
2409
Z_PARAM_STRING (time_str , time_str_len )
2414
2410
Z_PARAM_OBJECT_OF_CLASS_OR_NULL (timezone_object , date_ce_timezone )
2415
2411
ZEND_PARSE_PARAMETERS_END ();
2416
2412
2417
- zend_replace_error_handling (EH_THROW , NULL , & error_handling );
2418
2413
php_date_initialize (Z_PHPDATE_P (ZEND_THIS ), time_str , time_str_len , NULL , timezone_object , PHP_DATE_INIT_CTOR );
2419
- zend_restore_error_handling (& error_handling );
2420
2414
}
2421
2415
/* }}} */
2422
2416
@@ -3678,35 +3672,35 @@ PHP_FUNCTION(timezone_location_get)
3678
3672
}
3679
3673
/* }}} */
3680
3674
3681
- static int date_interval_initialize (timelib_rel_time * * rt , /*const*/ char * format , size_t format_length ) /* {{{ */
3675
+ static bool date_interval_initialize (timelib_rel_time * * rt , /*const*/ char * format , size_t format_length ) /* {{{ */
3682
3676
{
3683
3677
timelib_time * b = NULL , * e = NULL ;
3684
3678
timelib_rel_time * p = NULL ;
3685
3679
int r = 0 ;
3686
- int retval = 0 ;
3680
+ bool retval = false ;
3687
3681
timelib_error_container * errors ;
3688
3682
3689
3683
timelib_strtointerval (format , format_length , & b , & e , & p , & r , & errors );
3690
3684
3691
3685
if (errors -> error_count > 0 ) {
3692
- php_error_docref ( NULL , E_WARNING , "Unknown or bad format (%s)" , format );
3693
- retval = FAILURE ;
3686
+ zend_throw_error ( zend_ce_exception , "Unknown or bad format (%s)" , format );
3687
+ retval = false ;
3694
3688
if (p ) {
3695
3689
timelib_rel_time_dtor (p );
3696
3690
}
3697
3691
} else {
3698
3692
if (p ) {
3699
3693
* rt = p ;
3700
- retval = SUCCESS ;
3694
+ retval = true ;
3701
3695
} else {
3702
3696
if (b && e ) {
3703
3697
timelib_update_ts (b , NULL );
3704
3698
timelib_update_ts (e , NULL );
3705
3699
* rt = timelib_diff (b , e );
3706
- retval = SUCCESS ;
3700
+ retval = true ;
3707
3701
} else {
3708
- php_error_docref ( NULL , E_WARNING , "Failed to parse interval (%s)" , format );
3709
- retval = FAILURE ;
3702
+ zend_throw_error ( zend_ce_exception , "Failed to parse interval (%s)" , format );
3703
+ retval = false ;
3710
3704
}
3711
3705
}
3712
3706
}
@@ -3845,20 +3839,19 @@ PHP_METHOD(DateInterval, __construct)
3845
3839
{
3846
3840
zend_string * interval_string = NULL ;
3847
3841
timelib_rel_time * reltime ;
3848
- zend_error_handling error_handling ;
3849
3842
3850
3843
ZEND_PARSE_PARAMETERS_START (1 , 1 )
3851
3844
Z_PARAM_STR (interval_string )
3852
3845
ZEND_PARSE_PARAMETERS_END ();
3853
3846
3854
- zend_replace_error_handling (EH_THROW , NULL , & error_handling );
3855
- if (date_interval_initialize (& reltime , ZSTR_VAL (interval_string ), ZSTR_LEN (interval_string )) == SUCCESS ) {
3856
- php_interval_obj * diobj = Z_PHPINTERVAL_P (ZEND_THIS );
3857
- diobj -> diff = reltime ;
3858
- diobj -> initialized = 1 ;
3859
- diobj -> civil_or_wall = PHP_DATE_WALL ;
3847
+ if (!date_interval_initialize (& reltime , ZSTR_VAL (interval_string ), ZSTR_LEN (interval_string ))) {
3848
+ RETURN_THROWS ();
3860
3849
}
3861
- zend_restore_error_handling (& error_handling );
3850
+
3851
+ php_interval_obj * diobj = Z_PHPINTERVAL_P (ZEND_THIS );
3852
+ diobj -> diff = reltime ;
3853
+ diobj -> initialized = 1 ;
3854
+ diobj -> civil_or_wall = PHP_DATE_WALL ;
3862
3855
}
3863
3856
/* }}} */
3864
3857
@@ -4109,19 +4102,17 @@ PHP_FUNCTION(date_interval_format)
4109
4102
}
4110
4103
/* }}} */
4111
4104
4112
- static int date_period_initialize (timelib_time * * st , timelib_time * * et , timelib_rel_time * * d , zend_long * recurrences , /*const*/ char * format , size_t format_length ) /* {{{ */
4105
+ static void date_period_initialize (timelib_time * * st , timelib_time * * et , timelib_rel_time * * d , zend_long * recurrences , /*const*/ char * format , size_t format_length ) /* {{{ */
4113
4106
{
4114
4107
timelib_time * b = NULL , * e = NULL ;
4115
4108
timelib_rel_time * p = NULL ;
4116
4109
int r = 0 ;
4117
- int retval = 0 ;
4118
4110
timelib_error_container * errors ;
4119
4111
4120
4112
timelib_strtointerval (format , format_length , & b , & e , & p , & r , & errors );
4121
4113
4122
4114
if (errors -> error_count > 0 ) {
4123
- php_error_docref (NULL , E_WARNING , "Unknown or bad format (%s)" , format );
4124
- retval = FAILURE ;
4115
+ zend_throw_error (zend_ce_exception , "Unknown or bad format (%s)" , format );
4125
4116
if (b ) {
4126
4117
timelib_time_dtor (b );
4127
4118
}
@@ -4136,10 +4127,8 @@ static int date_period_initialize(timelib_time **st, timelib_time **et, timelib_
4136
4127
* et = e ;
4137
4128
* d = p ;
4138
4129
* recurrences = r ;
4139
- retval = SUCCESS ;
4140
4130
}
4141
4131
timelib_error_container_dtor (errors );
4142
- return retval ;
4143
4132
} /* }}} */
4144
4133
4145
4134
/* {{{ Creates new DatePeriod object. */
@@ -4152,7 +4141,6 @@ PHP_METHOD(DatePeriod, __construct)
4152
4141
char * isostr = NULL ;
4153
4142
size_t isostr_len = 0 ;
4154
4143
timelib_time * clone ;
4155
- zend_error_handling error_handling ;
4156
4144
4157
4145
if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , ZEND_NUM_ARGS (), "OOl|l" , & start , date_ce_interface , & interval , date_ce_interval , & recurrences , & options ) == FAILURE ) {
4158
4146
if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , ZEND_NUM_ARGS (), "OOO|l" , & start , date_ce_interface , & interval , date_ce_interval , & end , date_ce_interface , & options ) == FAILURE ) {
@@ -4167,9 +4155,7 @@ PHP_METHOD(DatePeriod, __construct)
4167
4155
dpobj -> current = NULL ;
4168
4156
4169
4157
if (isostr ) {
4170
- zend_replace_error_handling (EH_THROW , NULL , & error_handling );
4171
4158
date_period_initialize (& (dpobj -> start ), & (dpobj -> end ), & (dpobj -> interval ), & recurrences , isostr , isostr_len );
4172
- zend_restore_error_handling (& error_handling );
4173
4159
if (EG (exception )) {
4174
4160
RETURN_THROWS ();
4175
4161
}
0 commit comments