@@ -3213,7 +3213,7 @@ PHP_FUNCTION(date_format)
3213
3213
}
3214
3214
/* }}} */
3215
3215
3216
- static bool php_date_modify (zval * object , char * modify , size_t modify_len ) /* {{{ */
3216
+ static bool php_date_modify (zval * object , char * modify , size_t modify_len , const bool should_throw ) /* {{{ */
3217
3217
{
3218
3218
php_date_obj * dateobj ;
3219
3219
timelib_time * tmp_time ;
@@ -3233,10 +3233,22 @@ static bool php_date_modify(zval *object, char *modify, size_t modify_len) /* {{
3233
3233
3234
3234
if (err && err -> error_count ) {
3235
3235
/* spit out the first library error message, at least */
3236
- php_error_docref (NULL , E_WARNING , "Failed to parse time string (%s) at position %d (%c): %s" , modify ,
3237
- err -> error_messages [0 ].position ,
3238
- err -> error_messages [0 ].character ? err -> error_messages [0 ].character : ' ' ,
3239
- err -> error_messages [0 ].message );
3236
+ if (should_throw ) {
3237
+ zend_string * func_name = get_active_function_or_method_name ();
3238
+ zend_throw_exception_ex (date_ce_date_malformed_string_exception , 0 ,
3239
+ "%s(): Failed to parse time string (%s) at position %d (%c): %s" ,
3240
+ ZSTR_VAL (func_name ),
3241
+ modify ,
3242
+ err -> error_messages [0 ].position ,
3243
+ err -> error_messages [0 ].character ? err -> error_messages [0 ].character : ' ' ,
3244
+ err -> error_messages [0 ].message );
3245
+ zend_string_release_ex (func_name , false);
3246
+ } else {
3247
+ php_error_docref (NULL , E_WARNING , "Failed to parse time string (%s) at position %d (%c): %s" , modify ,
3248
+ err -> error_messages [0 ].position ,
3249
+ err -> error_messages [0 ].character ? err -> error_messages [0 ].character : ' ' ,
3250
+ err -> error_messages [0 ].message );
3251
+ }
3240
3252
timelib_time_dtor (tmp_time );
3241
3253
return 0 ;
3242
3254
}
@@ -3305,7 +3317,7 @@ PHP_FUNCTION(date_modify)
3305
3317
RETURN_THROWS ();
3306
3318
}
3307
3319
3308
- if (!php_date_modify (object , modify , modify_len )) {
3320
+ if (!php_date_modify (object , modify , modify_len , false )) {
3309
3321
RETURN_FALSE ;
3310
3322
}
3311
3323
@@ -3319,21 +3331,16 @@ PHP_METHOD(DateTime, modify)
3319
3331
zval * object ;
3320
3332
char * modify ;
3321
3333
size_t modify_len ;
3322
- zend_error_handling zeh ;
3323
3334
3324
3335
object = ZEND_THIS ;
3325
3336
ZEND_PARSE_PARAMETERS_START (1 , 1 )
3326
3337
Z_PARAM_STRING (modify , modify_len )
3327
3338
ZEND_PARSE_PARAMETERS_END ();
3328
3339
3329
- zend_replace_error_handling (EH_THROW , date_ce_date_malformed_string_exception , & zeh );
3330
- if (!php_date_modify (object , modify , modify_len )) {
3331
- zend_restore_error_handling (& zeh );
3340
+ if (!php_date_modify (object , modify , modify_len , true)) {
3332
3341
RETURN_THROWS ();
3333
3342
}
3334
3343
3335
- zend_restore_error_handling (& zeh );
3336
-
3337
3344
RETURN_OBJ_COPY (Z_OBJ_P (object ));
3338
3345
}
3339
3346
/* }}} */
@@ -3344,7 +3351,6 @@ PHP_METHOD(DateTimeImmutable, modify)
3344
3351
zval * object , new_object ;
3345
3352
char * modify ;
3346
3353
size_t modify_len ;
3347
- zend_error_handling zeh ;
3348
3354
3349
3355
object = ZEND_THIS ;
3350
3356
ZEND_PARSE_PARAMETERS_START (1 , 1 )
@@ -3353,15 +3359,11 @@ PHP_METHOD(DateTimeImmutable, modify)
3353
3359
3354
3360
date_clone_immutable (object , & new_object );
3355
3361
3356
- zend_replace_error_handling (EH_THROW , date_ce_date_malformed_string_exception , & zeh );
3357
- if (!php_date_modify (& new_object , modify , modify_len )) {
3362
+ if (!php_date_modify (& new_object , modify , modify_len , true)) {
3358
3363
zval_ptr_dtor (& new_object );
3359
- zend_restore_error_handling (& zeh );
3360
3364
RETURN_THROWS ();
3361
3365
}
3362
3366
3363
- zend_restore_error_handling (& zeh );
3364
-
3365
3367
RETURN_OBJ (Z_OBJ (new_object ));
3366
3368
}
3367
3369
/* }}} */
@@ -3418,7 +3420,7 @@ PHP_METHOD(DateTimeImmutable, add)
3418
3420
}
3419
3421
/* }}} */
3420
3422
3421
- static void php_date_sub (zval * object , zval * interval , zval * return_value ) /* {{{ */
3423
+ static void php_date_sub (zval * object , zval * interval , zval * return_value , const bool should_throw ) /* {{{ */
3422
3424
{
3423
3425
php_date_obj * dateobj ;
3424
3426
php_interval_obj * intobj ;
@@ -3430,7 +3432,15 @@ static void php_date_sub(zval *object, zval *interval, zval *return_value) /* {{
3430
3432
DATE_CHECK_INITIALIZED (intobj -> initialized , Z_OBJCE_P (interval ));
3431
3433
3432
3434
if (intobj -> diff -> have_weekday_relative || intobj -> diff -> have_special_relative ) {
3433
- php_error_docref (NULL , E_WARNING , "Only non-special relative time specifications are supported for subtraction" );
3435
+ if (should_throw ) {
3436
+ zend_string * func_name = get_active_function_or_method_name ();
3437
+ zend_throw_exception_ex (date_ce_date_invalid_operation_exception , 0 ,
3438
+ "%s(): Only non-special relative time specifications are supported for subtraction" ,
3439
+ ZSTR_VAL (func_name ));
3440
+ zend_string_release_ex (func_name , false);
3441
+ } else {
3442
+ php_error_docref (NULL , E_WARNING , "Only non-special relative time specifications are supported for subtraction" );
3443
+ }
3434
3444
return ;
3435
3445
}
3436
3446
@@ -3452,7 +3462,7 @@ PHP_FUNCTION(date_sub)
3452
3462
RETURN_THROWS ();
3453
3463
}
3454
3464
3455
- php_date_sub (object , interval , return_value );
3465
+ php_date_sub (object , interval , return_value , false );
3456
3466
RETURN_OBJ_COPY (Z_OBJ_P (object ));
3457
3467
}
3458
3468
/* }}} */
@@ -3461,15 +3471,12 @@ PHP_FUNCTION(date_sub)
3461
3471
PHP_METHOD (DateTime , sub )
3462
3472
{
3463
3473
zval * object , * interval ;
3464
- zend_error_handling zeh ;
3465
3474
3466
3475
if (zend_parse_method_parameters (ZEND_NUM_ARGS (), getThis (), "OO" , & object , date_ce_date , & interval , date_ce_interval ) == FAILURE ) {
3467
3476
RETURN_THROWS ();
3468
3477
}
3469
3478
3470
- zend_replace_error_handling (EH_THROW , date_ce_date_invalid_operation_exception , & zeh );
3471
- php_date_sub (object , interval , return_value );
3472
- zend_restore_error_handling (& zeh );
3479
+ php_date_sub (object , interval , return_value , true);
3473
3480
3474
3481
RETURN_OBJ_COPY (Z_OBJ_P (object ));
3475
3482
}
@@ -3479,7 +3486,6 @@ PHP_METHOD(DateTime, sub)
3479
3486
PHP_METHOD (DateTimeImmutable , sub )
3480
3487
{
3481
3488
zval * object , * interval , new_object ;
3482
- zend_error_handling zeh ;
3483
3489
3484
3490
object = ZEND_THIS ;
3485
3491
ZEND_PARSE_PARAMETERS_START (1 , 1 )
@@ -3488,9 +3494,7 @@ PHP_METHOD(DateTimeImmutable, sub)
3488
3494
3489
3495
date_clone_immutable (object , & new_object );
3490
3496
3491
- zend_replace_error_handling (EH_THROW , date_ce_date_invalid_operation_exception , & zeh );
3492
- php_date_sub (& new_object , interval , return_value );
3493
- zend_restore_error_handling (& zeh );
3497
+ php_date_sub (& new_object , interval , return_value , true);
3494
3498
3495
3499
RETURN_OBJ (Z_OBJ (new_object ));
3496
3500
}
0 commit comments