@@ -427,18 +427,10 @@ U_CFUNC PHP_METHOD(IntlCalendar, setDate)
427427 RETURN_THROWS ();
428428 }
429429
430- if (UNEXPECTED (year < INT32_MIN || year > INT32_MAX)) {
431- zend_argument_value_error (1 , " must be between %d and %d" , INT32_MIN, INT32_MAX);
432- RETURN_THROWS ();
433- }
434- if (UNEXPECTED (month < INT32_MIN || month > INT32_MAX)) {
435- zend_argument_value_error (2 , " must be between %d and %d" , INT32_MIN, INT32_MAX);
436- RETURN_THROWS ();
437- }
438- if (UNEXPECTED (day < INT32_MIN || day > INT32_MAX)) {
439- zend_argument_value_error (3 , " must be between %d and %d" , INT32_MIN, INT32_MAX);
440- RETURN_THROWS ();
441- }
430+ /* These method-only APIs parse the object first, so the API argument positions are offset by +1. */
431+ ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE (year, 2 );
432+ ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE (month, 3 );
433+ ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE (day, 4 );
442434
443435 CALENDAR_METHOD_FETCH_OBJECT;
444436
@@ -459,36 +451,19 @@ U_CFUNC PHP_METHOD(IntlCalendar, setDateTime)
459451 RETURN_THROWS ();
460452 }
461453
462- if (UNEXPECTED (year < INT32_MIN || year > INT32_MAX)) {
463- zend_argument_value_error (1 , " must be between %d and %d" , INT32_MIN, INT32_MAX);
464- RETURN_THROWS ();
465- }
466- if (UNEXPECTED (month < INT32_MIN || month > INT32_MAX)) {
467- zend_argument_value_error (2 , " must be between %d and %d" , INT32_MIN, INT32_MAX);
468- RETURN_THROWS ();
469- }
470- if (UNEXPECTED (day < INT32_MIN || day > INT32_MAX)) {
471- zend_argument_value_error (3 , " must be between %d and %d" , INT32_MIN, INT32_MAX);
472- RETURN_THROWS ();
473- }
474- if (UNEXPECTED (hour < INT32_MIN || hour > INT32_MAX)) {
475- zend_argument_value_error (4 , " must be between %d and %d" , INT32_MIN, INT32_MAX);
476- RETURN_THROWS ();
477- }
478- if (UNEXPECTED (minute < INT32_MIN || minute > INT32_MAX)) {
479- zend_argument_value_error (5 , " must be between %d and %d" , INT32_MIN, INT32_MAX);
480- RETURN_THROWS ();
481- }
454+ /* These method-only APIs parse the object first, so the API argument positions are offset by +1. */
455+ ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE (year, 2 );
456+ ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE (month, 3 );
457+ ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE (day, 4 );
458+ ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE (hour, 5 );
459+ ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE (minute, 6 );
482460
483461 CALENDAR_METHOD_FETCH_OBJECT;
484462
485463 if (second_is_null) {
486464 co->ucal ->set ((int32_t ) year, (int32_t ) month, (int32_t ) day, (int32_t ) hour, (int32_t ) minute);
487465 } else {
488- if (UNEXPECTED (second < INT32_MIN || second > INT32_MAX)) {
489- zend_argument_value_error (6 , " must be between %d and %d" , INT32_MIN, INT32_MAX);
490- RETURN_THROWS ();
491- }
466+ ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE (second, 7 );
492467 co->ucal ->set ((int32_t ) year, (int32_t ) month, (int32_t ) day, (int32_t ) hour, (int32_t ) minute, (int32_t ) second);
493468 }
494469}
0 commit comments