Commit 9f3a6f87961 for php

commit 9f3a6f87961e902e8e61432ba6e5d710e8cb0b2f
Merge: 11b7fd74461 d315d7ade85
Author: David Carlier <devnexen@gmail.com>
Date:   Thu Dec 3 02:58:23 2026 +0000

    Merge branch 'PHP-8.4' into PHP-8.5

    * PHP-8.4:
      ext/intl: Fix stale global error state in MessageFormatter and formatObject()

    # Conflicts:
    #       ext/intl/dateformat/dateformat_format_object.cpp
    #       ext/intl/msgformat/msgformat_attr.cpp
    #       ext/intl/msgformat/msgformat_format.cpp

diff --cc ext/intl/dateformat/dateformat_format_object.cpp
index a5113ce4cf9,e1ad7e20a77..5699f03a059
--- a/ext/intl/dateformat/dateformat_format_object.cpp
+++ b/ext/intl/dateformat/dateformat_format_object.cpp
@@@ -78,8 -77,10 +78,10 @@@ U_CFUNC PHP_FUNCTION(datefmt_format_obj
  	DateFormat::EStyle	dateStyle = DateFormat::kDefault,
  						timeStyle = DateFormat::kDefault;

+ 	intl_error_reset(NULL);
+
  	ZEND_PARSE_PARAMETERS_START(1, 3)
 -		Z_PARAM_OBJECT(object)
 +		Z_PARAM_OBJ(object)
  		Z_PARAM_OPTIONAL
  		Z_PARAM_ZVAL(format)
  		Z_PARAM_STRING_OR_NULL(locale_str, locale_len)
@@@ -161,24 -164,29 +163,24 @@@
  		date = obj_cal->getTime(status);
  		if (U_FAILURE(status)) {
  			intl_error_set(NULL, status,
 -					"datefmt_format_object: error obtaining instant from "
 -					"IntlCalendar", 0);
 -			RETVAL_FALSE;
 -			goto cleanup;
 +					"error obtaining instant from IntlCalendar");
 +			RETURN_FALSE;
  		}
 -		cal = obj_cal->clone();
 +		cal = std::unique_ptr<Calendar>(obj_cal->clone());
  	} else if (instanceof_function(instance_ce, php_date_get_interface_ce())) {
 -		if (intl_datetime_decompose(object, &date, &timeZone, NULL,
 -				"datefmt_format_object") == FAILURE) {
 +		TimeZone *tz;
 +		if (intl_datetime_decompose(object, &date, &tz, NULL) == FAILURE) {
  			RETURN_FALSE;
  		}
 -		cal = new GregorianCalendar(Locale::createFromName(locale_str), status);
 +		timeZone = std::unique_ptr<TimeZone>(tz);
 +		cal = std::unique_ptr<Calendar>(new GregorianCalendar(Locale::createFromName(locale_str), status));
  		if (U_FAILURE(status)) {
 -			intl_error_set(NULL, status,
 -					"datefmt_format_object: could not create GregorianCalendar",
 -					0);
 -			RETVAL_FALSE;
 -			goto cleanup;
 +			intl_error_set(NULL, status, "could not create GregorianCalendar");
 +			RETURN_FALSE;
  		}
  	} else {
- 		intl_error_set(NULL, status, "the passed object must be an instance "
 -		intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_format_object: the passed object "
 -				"must be an instance of either IntlCalendar or DateTimeInterface",
 -				0);
++		intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "the passed object must be an instance "
 +			"of either IntlCalendar or DateTimeInterface");
  		RETURN_FALSE;
  	}

diff --cc ext/intl/msgformat/msgformat_attr.cpp
index da68ef6fa95,9670fc87160..c6f96a290c7
--- a/ext/intl/msgformat/msgformat_attr.cpp
+++ b/ext/intl/msgformat/msgformat_attr.cpp
@@@ -94,8 -84,10 +94,9 @@@ U_CFUNC PHP_FUNCTION( msgfmt_set_patter
  	}
  	if (U_FAILURE(INTL_DATA_ERROR_CODE(mfo))) {
  		char *msg;
 -		umsg_close(new_format);
  		spprintf(&msg, 0, "Error setting symbol value at line %d, offset %d", spattern_error.line, spattern_error.offset);
+ 		intl_error_set_code(NULL, INTL_DATA_ERROR_CODE(mfo));
 -		intl_errors_set_custom_msg(INTL_DATA_ERROR_P(mfo), msg, 1);
 +		intl_errors_set_custom_msg(INTL_DATA_ERROR_P(mfo), msg);
  		efree(msg);
  		RETURN_FALSE;
  	}
diff --cc ext/intl/msgformat/msgformat_format.cpp
index d337ba11604,53b9f598b02..d6da76de9a9
--- a/ext/intl/msgformat/msgformat_format.cpp
+++ b/ext/intl/msgformat/msgformat_format.cpp
@@@ -149,7 -149,8 +151,8 @@@ U_CFUNC PHP_FUNCTION( msgfmt_format_mes

  			efree( msg );
  		} else {
+ 			intl_error_set_code(/* intl_error* */ NULL, INTL_DATA_ERROR_CODE( mfo ) );
 -			intl_errors_set_custom_msg(/* intl_error* */ NULL, "Creating message formatter failed", 0 );
 +			intl_errors_set_custom_msg(/* intl_error* */ NULL, "Creating message formatter failed");
  		}
  		umsg_close(MSG_FORMAT_OBJECT(mfo));
  		RETURN_FALSE;
diff --cc ext/intl/tests/dateformat_formatObject_error.phpt
index b38a379b9f5,839cb27d317..3bef3346d99
--- a/ext/intl/tests/dateformat_formatObject_error.phpt
+++ b/ext/intl/tests/dateformat_formatObject_error.phpt
@@@ -2,59 -2,56 +2,59 @@@
  IntlDateFormatter::formatObject(): error conditions
  --EXTENSIONS--
  intl
 +--INI--
 +intl.default_locale=pt_PT
 +date.timezone=Europe/Lisbon
  --FILE--
  <?php
 -ini_set("intl.error_level", E_WARNING);
 -ini_set("intl.default_locale", "pt_PT");
 -ini_set("date.timezone", "Europe/Lisbon");
 -
 -var_dump(IntlDateFormatter::formatObject(new stdclass));

  class A extends IntlCalendar {function __construct(){}}
 -var_dump(IntlDateFormatter::formatObject(new A));
 +
  class B extends DateTime {function __construct(){}}
 +
 +$cal = IntlCalendar::createInstance();
 +
  try {
      var_dump(IntlDateFormatter::formatObject(new B));
 -} catch (Error $e) {
 -    echo $e->getMessage(), "\n";
 +    var_dump(intl_get_error_message());
 +} catch (Throwable $e) {
 +    echo $e::class, ': ', $e->getMessage(), "\n";
  }

 -$cal = IntlCalendar::createInstance();
 +var_dump(IntlDateFormatter::formatObject(new stdclass));
 +var_dump(intl_get_error_message());
 +var_dump(IntlDateFormatter::formatObject(new A));
 +var_dump(intl_get_error_message());
 +
  var_dump(IntlDateFormatter::formatObject($cal, -2));
 +var_dump(intl_get_error_message());
  var_dump(IntlDateFormatter::formatObject($cal, array()));
 +var_dump(intl_get_error_message());
  var_dump(IntlDateFormatter::formatObject($cal, array(1,2,3)));
 +var_dump(intl_get_error_message());
  var_dump(IntlDateFormatter::formatObject($cal, array(array(), 1)));
 +var_dump(intl_get_error_message());
  var_dump(IntlDateFormatter::formatObject($cal, array(1, -2)));
 +var_dump(intl_get_error_message());
  var_dump(IntlDateFormatter::formatObject($cal, ""));
 +var_dump(intl_get_error_message());

  ?>
 ---EXPECTF--
 -Warning: IntlDateFormatter::formatObject(): datefmt_format_object: the passed object must be an instance of either IntlCalendar or DateTimeInterface in %s on line %d
 +--EXPECT--
 +DateObjectError: Object of type B (inheriting DateTime) has not been correctly initialized by calling parent::__construct() in its constructor
  bool(false)
- string(130) "IntlDateFormatter::formatObject(): the passed object must be an instance of either IntlCalendar or DateTimeInterface: U_ZERO_ERROR"
 -
 -Warning: IntlDateFormatter::formatObject(): datefmt_format_object: bad IntlCalendar instance: not initialized properly in %s on line %d
++string(142) "IntlDateFormatter::formatObject(): the passed object must be an instance of either IntlCalendar or DateTimeInterface: U_ILLEGAL_ARGUMENT_ERROR"
  bool(false)
 -
 -Warning: IntlDateFormatter::formatObject(): datefmt_format_object: error calling ::getTimeStamp() on the object in %s on line %d
 -Object of type B (inheriting DateTime) has not been correctly initialized by calling parent::__construct() in its constructor
 -
 -Warning: IntlDateFormatter::formatObject(): datefmt_format_object: the date/time format type is invalid in %s on line %d
 +string(112) "IntlDateFormatter::formatObject(): bad IntlCalendar instance: not initialized properly: U_ILLEGAL_ARGUMENT_ERROR"
  bool(false)
 -
 -Warning: IntlDateFormatter::formatObject(): datefmt_format_object: bad format; if array, it must have two elements in %s on line %d
 +string(97) "IntlDateFormatter::formatObject(): the date/time format type is invalid: U_ILLEGAL_ARGUMENT_ERROR"
  bool(false)
 -
 -Warning: IntlDateFormatter::formatObject(): datefmt_format_object: bad format; if array, it must have two elements in %s on line %d
 +string(108) "IntlDateFormatter::formatObject(): bad format; if array, it must have two elements: U_ILLEGAL_ARGUMENT_ERROR"
  bool(false)
 -
 -Warning: IntlDateFormatter::formatObject(): datefmt_format_object: bad format; the date format (first element of the array) is not valid in %s on line %d
 +string(108) "IntlDateFormatter::formatObject(): bad format; if array, it must have two elements: U_ILLEGAL_ARGUMENT_ERROR"
  bool(false)
 -
 -Warning: IntlDateFormatter::formatObject(): datefmt_format_object: bad format; the time format (second element of the array) is not valid in %s on line %d
 +string(130) "IntlDateFormatter::formatObject(): bad format; the date format (first element of the array) is not valid: U_ILLEGAL_ARGUMENT_ERROR"
  bool(false)
 -
 -Warning: IntlDateFormatter::formatObject(): datefmt_format_object: the format is empty in %s on line %d
 +string(131) "IntlDateFormatter::formatObject(): bad format; the time format (second element of the array) is not valid: U_ILLEGAL_ARGUMENT_ERROR"
  bool(false)
 +string(80) "IntlDateFormatter::formatObject(): the format is empty: U_ILLEGAL_ARGUMENT_ERROR"
diff --cc ext/intl/tests/msgfmt_format_message_errors.phpt
index 8a5ee8ea2ea,00000000000..dd561b0c838
mode 100644,000000..100644
--- a/ext/intl/tests/msgfmt_format_message_errors.phpt
+++ b/ext/intl/tests/msgfmt_format_message_errors.phpt
@@@ -1,27 -1,0 +1,27 @@@
 +--TEST--
 +MessageFormatter::parseMessage() with invalid locale
 +--EXTENSIONS--
 +intl
 +--FILE--
 +<?php
 +
 +$locale = 'root';
 +$fmt = '{0,whatever} would not work!';
 +$m = 4560;
 +$t = 123;
 +$v = [$m, $t, $m/$t];
 +
 +$m = MessageFormatter::formatMessage($locale, $fmt, $v);
 +var_dump($m);
 +var_dump(intl_get_error_message());
 +
 +$m = msgfmt_format_message($locale, $fmt, $v);
 +var_dump($m);
 +var_dump(intl_get_error_message());
 +
 +?>
 +--EXPECT--
 +bool(false)
- string(82) "MessageFormatter::formatMessage(): Creating message formatter failed: U_ZERO_ERROR"
++string(94) "MessageFormatter::formatMessage(): Creating message formatter failed: U_ILLEGAL_ARGUMENT_ERROR"
 +bool(false)
- string(72) "msgfmt_format_message(): Creating message formatter failed: U_ZERO_ERROR"
++string(84) "msgfmt_format_message(): Creating message formatter failed: U_ILLEGAL_ARGUMENT_ERROR"