@@ -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_exception_ex (NULL , 0 , "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
@@ -3686,35 +3680,35 @@ PHP_FUNCTION(timezone_location_get)
3686
3680
}
3687
3681
/* }}} */
3688
3682
3689
- static int date_interval_initialize (timelib_rel_time * * rt , /*const*/ char * format , size_t format_length ) /* {{{ */
3683
+ static bool date_interval_initialize (timelib_rel_time * * rt , /*const*/ char * format , size_t format_length ) /* {{{ */
3690
3684
{
3691
3685
timelib_time * b = NULL , * e = NULL ;
3692
3686
timelib_rel_time * p = NULL ;
3693
3687
int r = 0 ;
3694
- int retval = 0 ;
3688
+ bool retval = false ;
3695
3689
timelib_error_container * errors ;
3696
3690
3697
3691
timelib_strtointerval (format , format_length , & b , & e , & p , & r , & errors );
3698
3692
3699
3693
if (errors -> error_count > 0 ) {
3700
- php_error_docref (NULL , E_WARNING , "Unknown or bad format (%s)" , format );
3701
- retval = FAILURE ;
3694
+ zend_throw_exception_ex (NULL , 0 , "Unknown or bad format (%s)" , format );
3695
+ retval = false ;
3702
3696
if (p ) {
3703
3697
timelib_rel_time_dtor (p );
3704
3698
}
3705
3699
} else {
3706
3700
if (p ) {
3707
3701
* rt = p ;
3708
- retval = SUCCESS ;
3702
+ retval = true ;
3709
3703
} else {
3710
3704
if (b && e ) {
3711
3705
timelib_update_ts (b , NULL );
3712
3706
timelib_update_ts (e , NULL );
3713
3707
* rt = timelib_diff (b , e );
3714
- retval = SUCCESS ;
3708
+ retval = true ;
3715
3709
} else {
3716
- php_error_docref (NULL , E_WARNING , "Failed to parse interval (%s)" , format );
3717
- retval = FAILURE ;
3710
+ zend_throw_exception_ex (NULL , 0 , "Failed to parse interval (%s)" , format );
3711
+ retval = false ;
3718
3712
}
3719
3713
}
3720
3714
}
@@ -3853,20 +3847,19 @@ PHP_METHOD(DateInterval, __construct)
3853
3847
{
3854
3848
zend_string * interval_string = NULL ;
3855
3849
timelib_rel_time * reltime ;
3856
- zend_error_handling error_handling ;
3857
3850
3858
3851
ZEND_PARSE_PARAMETERS_START (1 , 1 )
3859
3852
Z_PARAM_STR (interval_string )
3860
3853
ZEND_PARSE_PARAMETERS_END ();
3861
3854
3862
- zend_replace_error_handling (EH_THROW , NULL , & error_handling );
3863
- if (date_interval_initialize (& reltime , ZSTR_VAL (interval_string ), ZSTR_LEN (interval_string )) == SUCCESS ) {
3864
- php_interval_obj * diobj = Z_PHPINTERVAL_P (ZEND_THIS );
3865
- diobj -> diff = reltime ;
3866
- diobj -> initialized = 1 ;
3867
- diobj -> civil_or_wall = PHP_DATE_WALL ;
3855
+ if (!date_interval_initialize (& reltime , ZSTR_VAL (interval_string ), ZSTR_LEN (interval_string ))) {
3856
+ RETURN_THROWS ();
3868
3857
}
3869
- zend_restore_error_handling (& error_handling );
3858
+
3859
+ php_interval_obj * diobj = Z_PHPINTERVAL_P (ZEND_THIS );
3860
+ diobj -> diff = reltime ;
3861
+ diobj -> initialized = 1 ;
3862
+ diobj -> civil_or_wall = PHP_DATE_WALL ;
3870
3863
}
3871
3864
/* }}} */
3872
3865
@@ -4117,19 +4110,19 @@ PHP_FUNCTION(date_interval_format)
4117
4110
}
4118
4111
/* }}} */
4119
4112
4120
- 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 ) /* {{{ */
4113
+ static bool date_period_initialize (timelib_time * * st , timelib_time * * et , timelib_rel_time * * d , zend_long * recurrences , /*const*/ char * format , size_t format_length ) /* {{{ */
4121
4114
{
4122
4115
timelib_time * b = NULL , * e = NULL ;
4123
4116
timelib_rel_time * p = NULL ;
4124
4117
int r = 0 ;
4125
- int retval = 0 ;
4126
4118
timelib_error_container * errors ;
4119
+ bool retval = false;
4127
4120
4128
4121
timelib_strtointerval (format , format_length , & b , & e , & p , & r , & errors );
4129
4122
4130
4123
if (errors -> error_count > 0 ) {
4131
- php_error_docref ( NULL , E_WARNING , "Unknown or bad format (%s)" , format ) ;
4132
- retval = FAILURE ;
4124
+ retval = false ;
4125
+ zend_throw_exception_ex ( NULL , 0 , "Unknown or bad format (%s)" , format ) ;
4133
4126
if (b ) {
4134
4127
timelib_time_dtor (b );
4135
4128
}
@@ -4144,7 +4137,7 @@ static int date_period_initialize(timelib_time **st, timelib_time **et, timelib_
4144
4137
* et = e ;
4145
4138
* d = p ;
4146
4139
* recurrences = r ;
4147
- retval = SUCCESS ;
4140
+ retval = true ;
4148
4141
}
4149
4142
timelib_error_container_dtor (errors );
4150
4143
return retval ;
@@ -4160,7 +4153,6 @@ PHP_METHOD(DatePeriod, __construct)
4160
4153
char * isostr = NULL ;
4161
4154
size_t isostr_len = 0 ;
4162
4155
timelib_time * clone ;
4163
- zend_error_handling error_handling ;
4164
4156
4165
4157
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 ) {
4166
4158
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 ) {
@@ -4175,28 +4167,25 @@ PHP_METHOD(DatePeriod, __construct)
4175
4167
dpobj -> current = NULL ;
4176
4168
4177
4169
if (isostr ) {
4178
- zend_replace_error_handling (EH_THROW , NULL , & error_handling );
4179
- date_period_initialize (& (dpobj -> start ), & (dpobj -> end ), & (dpobj -> interval ), & recurrences , isostr , isostr_len );
4180
- zend_restore_error_handling (& error_handling );
4181
- if (EG (exception )) {
4170
+ if (!date_period_initialize (& (dpobj -> start ), & (dpobj -> end ), & (dpobj -> interval ), & recurrences , isostr , isostr_len )) {
4182
4171
RETURN_THROWS ();
4183
4172
}
4184
4173
4185
4174
if (dpobj -> start == NULL ) {
4186
4175
zend_string * func = get_active_function_or_method_name ();
4187
- zend_throw_error ( zend_ce_exception , "%s(): ISO interval must contain a start date, \"%s\" given" , ZSTR_VAL (func ), isostr );
4176
+ zend_throw_exception_ex ( NULL , 0 , "%s(): ISO interval must contain a start date, \"%s\" given" , ZSTR_VAL (func ), isostr );
4188
4177
zend_string_release (func );
4189
4178
RETURN_THROWS ();
4190
4179
}
4191
4180
if (dpobj -> interval == NULL ) {
4192
4181
zend_string * func = get_active_function_or_method_name ();
4193
- zend_throw_error ( zend_ce_exception , "%s(): ISO interval must contain an interval, \"%s\" given" , ZSTR_VAL (func ), isostr );
4182
+ zend_throw_exception_ex ( NULL , 0 , "%s(): ISO interval must contain an interval, \"%s\" given" , ZSTR_VAL (func ), isostr );
4194
4183
zend_string_release (func );
4195
4184
RETURN_THROWS ();
4196
4185
}
4197
4186
if (dpobj -> end == NULL && recurrences == 0 ) {
4198
4187
zend_string * func = get_active_function_or_method_name ();
4199
- zend_throw_error ( zend_ce_exception , "%s(): ISO interval must contain an end date or a recurrence count, \"%s\" given" , ZSTR_VAL (func ), isostr );
4188
+ zend_throw_exception_ex ( NULL , 0 , "%s(): ISO interval must contain an end date or a recurrence count, \"%s\" given" , ZSTR_VAL (func ), isostr );
4200
4189
zend_string_release (func );
4201
4190
RETURN_THROWS ();
4202
4191
}
@@ -4238,7 +4227,7 @@ PHP_METHOD(DatePeriod, __construct)
4238
4227
4239
4228
if (dpobj -> end == NULL && recurrences < 1 ) {
4240
4229
zend_string * func = get_active_function_or_method_name ();
4241
- zend_throw_error ( zend_ce_exception , "%s(): Recurrence count must be greater than 0" , ZSTR_VAL (func ));
4230
+ zend_throw_exception_ex ( NULL , 0 , "%s(): Recurrence count must be greater than 0" , ZSTR_VAL (func ));
4242
4231
zend_string_release (func );
4243
4232
RETURN_THROWS ();
4244
4233
}
0 commit comments