Merge branch 'PHP-8.1'

* PHP-8.1:
  Allowing catching arg type deprecations in intl classes
This commit is contained in:
Ilija Tovilo 2022-03-03 11:27:46 +01:00
commit 51f750ea46
No known key found for this signature in database
GPG key ID: A4F5D403F118200A
9 changed files with 133 additions and 39 deletions

View file

@ -31,7 +31,7 @@ static inline RuleBasedBreakIterator *fetch_rbbi(BreakIterator_object *bio) {
return (RuleBasedBreakIterator*)bio->biter;
}
static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced)
{
char *rules;
size_t rules_len;
@ -51,6 +51,9 @@ static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
RETURN_THROWS();
}
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
*error_handling_replaced = 1;
// instantiation of ICU object
RuleBasedBreakIterator *rbbi;
@ -95,12 +98,14 @@ static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
U_CFUNC PHP_METHOD(IntlRuleBasedBreakIterator, __construct)
{
zend_error_handling error_handling;
bool error_handling_replaced = 0;
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
return_value = ZEND_THIS;
_php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU);
_php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced);
if (error_handling_replaced) {
zend_restore_error_handling(&error_handling);
}
}
U_CFUNC PHP_METHOD(IntlRuleBasedBreakIterator, getRules)
{

View file

@ -44,7 +44,7 @@ static inline GregorianCalendar *fetch_greg(Calendar_object *co) {
}
static void _php_intlgregcal_constructor_body(
INTERNAL_FUNCTION_PARAMETERS, bool is_constructor)
INTERNAL_FUNCTION_PARAMETERS, bool is_constructor, zend_error_handling *error_handling, bool *error_handling_replaced)
{
zval *tz_object = NULL;
zval args_a[6],
@ -84,6 +84,11 @@ static void _php_intlgregcal_constructor_body(
RETURN_THROWS();
}
if (error_handling != NULL) {
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
*error_handling_replaced = 1;
}
// instantion of ICU object
Calendar_object *co = Z_INTL_CALENDAR_P(return_value);
GregorianCalendar *gcal = NULL;
@ -188,18 +193,20 @@ U_CFUNC PHP_FUNCTION(intlgregcal_create_instance)
intl_error_reset(NULL);
object_init_ex(return_value, GregorianCalendar_ce_ptr);
_php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
_php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, /* is_constructor */ 0, NULL, NULL);
}
U_CFUNC PHP_METHOD(IntlGregorianCalendar, __construct)
{
zend_error_handling error_handling;
bool error_handling_replaced = 0;
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
return_value = ZEND_THIS;
_php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
_php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, /* is_constructor */ 1, &error_handling, &error_handling_replaced);
if (error_handling_replaced) {
zend_restore_error_handling(&error_handling);
}
}
U_CFUNC PHP_FUNCTION(intlgregcal_set_gregorian_change)
{

View file

@ -22,7 +22,7 @@
#include "intl_data.h"
/* {{{ */
static int collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
static int collator_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced)
{
const char* locale;
size_t locale_len = 0;
@ -38,6 +38,11 @@ static int collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
return FAILURE;
}
if (error_handling != NULL) {
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
*error_handling_replaced = 1;
}
INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len);
COLLATOR_METHOD_FETCH_OBJECT;
@ -56,7 +61,7 @@ static int collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
PHP_FUNCTION( collator_create )
{
object_init_ex( return_value, Collator_ce_ptr );
if (collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
if (collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL, NULL) == FAILURE) {
zval_ptr_dtor(return_value);
RETURN_NULL();
}
@ -67,14 +72,16 @@ PHP_FUNCTION( collator_create )
PHP_METHOD( Collator, __construct )
{
zend_error_handling error_handling;
bool error_handling_replaced = 0;
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
return_value = ZEND_THIS;
if (collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
if (collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced) == FAILURE) {
if (!EG(exception)) {
zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
}
}
if (error_handling_replaced) {
zend_restore_error_handling(&error_handling);
}
}
/* }}} */

View file

@ -45,7 +45,7 @@ extern "C" {
UDAT_PATTERN == (i))
/* {{{ */
static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced)
{
zval *object;
char *locale_str;
@ -81,6 +81,11 @@ static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
Z_PARAM_STRING_OR_NULL(pattern_str, pattern_str_len)
ZEND_PARSE_PARAMETERS_END_EX(return FAILURE);
if (error_handling != NULL) {
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
*error_handling_replaced = 1;
}
DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK;
if (DATE_FORMAT_OBJECT(dfo) != NULL) {
@ -189,7 +194,7 @@ error:
U_CFUNC PHP_FUNCTION( datefmt_create )
{
object_init_ex( return_value, IntlDateFormatter_ce_ptr );
if (datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
if (datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL, NULL) == FAILURE) {
zval_ptr_dtor(return_value);
RETURN_NULL();
}
@ -200,18 +205,20 @@ U_CFUNC PHP_FUNCTION( datefmt_create )
U_CFUNC PHP_METHOD( IntlDateFormatter, __construct )
{
zend_error_handling error_handling;
bool error_handling_replaced = 0;
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
/* return_value param is being changed, therefore we will always return
* NULL here */
return_value = ZEND_THIS;
if (datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
if (datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced) == FAILURE) {
if (!EG(exception)) {
zend_string *err = intl_error_get_message(NULL);
zend_throw_exception(IntlException_ce_ptr, ZSTR_VAL(err), intl_error_get_code(NULL));
zend_string_release_ex(err, 0);
}
}
if (error_handling_replaced) {
zend_restore_error_handling(&error_handling);
}
}
/* }}} */

View file

@ -30,7 +30,7 @@ using icu::DateTimePatternGenerator;
using icu::Locale;
using icu::StringPiece;
static zend_result dtpg_ctor(INTERNAL_FUNCTION_PARAMETERS)
static zend_result dtpg_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced)
{
char *locale_str;
size_t locale_len = 0;
@ -44,6 +44,11 @@ static zend_result dtpg_ctor(INTERNAL_FUNCTION_PARAMETERS)
Z_PARAM_STRING_OR_NULL(locale_str, locale_len)
ZEND_PARSE_PARAMETERS_END_EX(return FAILURE);
if (error_handling != NULL) {
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
*error_handling_replaced = 1;
}
DTPATTERNGEN_METHOD_FETCH_OBJECT_NO_CHECK;
if (dtpgo->dtpg != NULL) {
@ -74,7 +79,7 @@ static zend_result dtpg_ctor(INTERNAL_FUNCTION_PARAMETERS)
U_CFUNC PHP_METHOD( IntlDatePatternGenerator, create )
{
object_init_ex( return_value, IntlDatePatternGenerator_ce_ptr );
if (dtpg_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
if (dtpg_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL, NULL) == FAILURE) {
zval_ptr_dtor(return_value);
RETURN_NULL();
}
@ -83,20 +88,22 @@ U_CFUNC PHP_METHOD( IntlDatePatternGenerator, create )
U_CFUNC PHP_METHOD( IntlDatePatternGenerator, __construct )
{
zend_error_handling error_handling;
bool error_handling_replaced = 0;
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
/* return_value param is being changed, therefore we will always return
* NULL here */
return_value = ZEND_THIS;
if (dtpg_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
if (dtpg_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced) == FAILURE) {
if (!EG(exception)) {
zend_string *err = intl_error_get_message(NULL);
zend_throw_exception(IntlException_ce_ptr, ZSTR_VAL(err), intl_error_get_code(NULL));
zend_string_release_ex(err, 0);
}
}
if (error_handling_replaced) {
zend_restore_error_handling(&error_handling);
}
}
U_CFUNC PHP_METHOD( IntlDatePatternGenerator, getBestPattern )

View file

@ -23,7 +23,7 @@
#include "intl_convert.h"
/* {{{ */
static int numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
static int numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced)
{
const char* locale;
char* pattern = NULL;
@ -40,6 +40,11 @@ static int numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
return FAILURE;
}
if (error_handling != NULL) {
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
*error_handling_replaced = 1;
}
INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len);
object = return_value;
FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK;
@ -74,7 +79,7 @@ static int numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
PHP_FUNCTION( numfmt_create )
{
object_init_ex( return_value, NumberFormatter_ce_ptr );
if (numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
if (numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL, NULL) == FAILURE) {
zval_ptr_dtor(return_value);
RETURN_NULL();
}
@ -85,16 +90,18 @@ PHP_FUNCTION( numfmt_create )
PHP_METHOD( NumberFormatter, __construct )
{
zend_error_handling error_handling;
bool error_handling_replaced = 0;
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
return_value = ZEND_THIS;
if (numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
if (numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced) == FAILURE) {
if (!EG(exception)) {
zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
}
}
if (error_handling_replaced) {
zend_restore_error_handling(&error_handling);
}
}
/* }}} */
/* {{{ Get formatter's last error code. */

View file

@ -25,7 +25,7 @@
#include "intl_convert.h"
/* {{{ */
static int msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
static int msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced)
{
const char* locale;
char* pattern;
@ -45,6 +45,11 @@ static int msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
return FAILURE;
}
if (error_handling != NULL) {
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
*error_handling_replaced = 1;
}
INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len);
MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK;
@ -104,7 +109,7 @@ static int msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
PHP_FUNCTION( msgfmt_create )
{
object_init_ex( return_value, MessageFormatter_ce_ptr );
if (msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
if (msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL, NULL) == FAILURE) {
zval_ptr_dtor(return_value);
RETURN_NULL();
}
@ -115,18 +120,20 @@ PHP_FUNCTION( msgfmt_create )
PHP_METHOD( MessageFormatter, __construct )
{
zend_error_handling error_handling;
bool error_handling_replaced = 0;
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
return_value = ZEND_THIS;
if (msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
if (msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced) == FAILURE) {
if (!EG(exception)) {
zend_string *err = intl_error_get_message(NULL);
zend_throw_exception(IntlException_ce_ptr, ZSTR_VAL(err), intl_error_get_code(NULL));
zend_string_release_ex(err, 0);
}
}
if (error_handling_replaced) {
zend_restore_error_handling(&error_handling);
}
}
/* }}} */
/* {{{ Get formatter's last error code. */

View file

@ -74,7 +74,7 @@ static zend_object *ResourceBundle_object_create( zend_class_entry *ce )
/* }}} */
/* {{{ ResourceBundle_ctor */
static int resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS)
static int resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced)
{
const char *bundlename;
size_t bundlename_len = 0;
@ -93,6 +93,11 @@ static int resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS)
return FAILURE;
}
if (error_handling != NULL) {
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
*error_handling_replaced = 1;
}
if (rb->me) {
zend_throw_error(NULL, "ResourceBundle object is already constructed");
return FAILURE;
@ -139,23 +144,25 @@ static int resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS)
PHP_METHOD( ResourceBundle, __construct )
{
zend_error_handling error_handling;
bool error_handling_replaced = 0;
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
return_value = ZEND_THIS;
if (resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
if (resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced) == FAILURE) {
if (!EG(exception)) {
zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
}
}
if (error_handling_replaced) {
zend_restore_error_handling(&error_handling);
}
}
/* }}} */
/* {{{ */
PHP_FUNCTION( resourcebundle_create )
{
object_init_ex( return_value, ResourceBundle_ce_ptr );
if (resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
if (resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL, NULL) == FAILURE) {
zval_ptr_dtor(return_value);
RETURN_NULL();
}

View file

@ -0,0 +1,40 @@
--TEST--
GH-8115 (Can't catch deprecation in IntlDateFormatter)
--EXTENSIONS--
intl
--FILE--
<?php
error_reporting(E_ALL);
set_error_handler(function ($errNo, $errStr) {
echo "Caught ($errNo): $errStr\n";
});
try {
new \IntlDateFormatter(null, null, null);
} catch (\IntlException) {}
try {
new \IntlRuleBasedBreakIterator(null, null);
} catch (\IntlException) {}
// Can't be tested since all params are optional
new \IntlGregorianCalendar(null, null);
new \Collator(null);
// Can't be tested since all params are optional
new \IntlDatePatternGenerator(null);
new \NumberFormatter(null, null);
try {
new \MessageFormatter(null, null);
} catch (\IntlException) {}
new \ResourceBundle(null, null, null);
?>
--EXPECT--
Caught (8192): IntlDateFormatter::__construct(): Passing null to parameter #2 ($dateType) of type int is deprecated
Caught (8192): IntlDateFormatter::__construct(): Passing null to parameter #3 ($timeType) of type int is deprecated
Caught (8192): IntlRuleBasedBreakIterator::__construct(): Passing null to parameter #1 ($rules) of type string is deprecated
Caught (8192): IntlRuleBasedBreakIterator::__construct(): Passing null to parameter #2 ($compiled) of type bool is deprecated
Caught (8192): Collator::__construct(): Passing null to parameter #1 ($locale) of type string is deprecated
Caught (8192): NumberFormatter::__construct(): Passing null to parameter #1 ($locale) of type string is deprecated
Caught (8192): NumberFormatter::__construct(): Passing null to parameter #2 ($style) of type int is deprecated
Caught (8192): MessageFormatter::__construct(): Passing null to parameter #1 ($locale) of type string is deprecated
Caught (8192): MessageFormatter::__construct(): Passing null to parameter #2 ($pattern) of type string is deprecated
Caught (8192): ResourceBundle::__construct(): Passing null to parameter #3 ($fallback) of type bool is deprecated