[php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6
| From: | Ilia Alshanetsky | Date: | Tue, 22 Sep 2026 12:46:08 +0000 |
| Subject: | [php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141395@lists.php.net to get a copy of this message | ||
Author: Ilia Alshanetsky (iliaal)
Date: 2026-09-22T08:32:06-04:00
Commit: https://github.com/php/php-src/commit/fe96b7a7bcb627a3ffc7c65d7da12a08038fa405
Raw diff: https://github.com/php/php-src/commit/fe96b7a7bcb627a3ffc7c65d7da12a08038fa405.diff
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5:
ext/intl: Reject unconstructed Collator in attribute and strength methods
Changed paths:
A ext/intl/tests/collator_attribute_unconstructed.phpt
M NEWS
M ext/intl/collator/collator_attr.cpp
M ext/intl/collator/collator_class.h
M ext/intl/collator/collator_compare.cpp
M ext/intl/collator/collator_locale.cpp
M ext/intl/collator/collator_sort.cpp
Diff:
diff --git a/NEWS b/NEWS
index 02da37e81086..a5b12c6de207 100644
--- a/NEWS
+++ b/NEWS
@@ -43,6 +43,8 @@ PHP NEWS
(Ilia Alshanetsky)
. Fixed a crash when converting with a cloned UConverter that uses
toUCallback/fromUCallback. (Ilia Alshanetsky)
+ . Fixed Collator attribute and strength methods not rejecting an
+ unconstructed Collator. (Ilia Alshanetsky)
- Lexbor:
. Merge patches lexbor/lexbor@8a14bc0 and lexbor/lexbor@f67ce4b, fixing a
diff --git a/ext/intl/collator/collator_attr.cpp b/ext/intl/collator/collator_attr.cpp
index 14b8abf497b4..04ce848abe0b 100644
--- a/ext/intl/collator/collator_attr.cpp
+++ b/ext/intl/collator/collator_attr.cpp
@@ -47,6 +47,10 @@ U_CFUNC PHP_FUNCTION( collator_get_attribute )
/* Fetch the object. */
COLLATOR_METHOD_FETCH_OBJECT;
+ if (collator_check_initialized(co) == FAILURE) {
+ RETURN_THROWS();
+ }
+
value = ucol_getAttribute( co->ucoll, static_cast<UColAttribute>(attribute),
COLLATOR_ERROR_CODE_P( co ) );
COLLATOR_CHECK_STATUS( co, "Error getting attribute value" );
@@ -71,6 +75,10 @@ U_CFUNC PHP_FUNCTION( collator_set_attribute )
/* Fetch the object. */
COLLATOR_METHOD_FETCH_OBJECT;
+ if (collator_check_initialized(co) == FAILURE) {
+ RETURN_THROWS();
+ }
+
/* Set new value for the given attribute. */
ucol_setAttribute( co->ucoll, static_cast<UColAttribute>(attribute),
static_cast<UColAttributeValue>(value), COLLATOR_ERROR_CODE_P( co ) );
COLLATOR_CHECK_STATUS( co, "Error setting attribute value" );
@@ -94,6 +102,10 @@ U_CFUNC PHP_FUNCTION( collator_get_strength )
/* Fetch the object. */
COLLATOR_METHOD_FETCH_OBJECT;
+ if (collator_check_initialized(co) == FAILURE) {
+ RETURN_THROWS();
+ }
+
/* Get current strength and return it. */
RETURN_LONG( ucol_getStrength( co->ucoll ) );
}
@@ -116,6 +128,10 @@ U_CFUNC PHP_FUNCTION( collator_set_strength )
/* Fetch the object. */
COLLATOR_METHOD_FETCH_OBJECT;
+ if (collator_check_initialized(co) == FAILURE) {
+ RETURN_THROWS();
+ }
+
/* Set given strength. */
ucol_setStrength( co->ucoll, static_cast<UColAttributeValue>(strength) );
diff --git a/ext/intl/collator/collator_class.h b/ext/intl/collator/collator_class.h
index 637d5dc490ae..c4be06fd1298 100644
--- a/ext/intl/collator/collator_class.h
+++ b/ext/intl/collator/collator_class.h
@@ -50,6 +50,21 @@ typedef struct {
#define php_intl_collator_fetch_object(obj) ZEND_CONTAINER_OF(obj, Collator_object, zo)
#define Z_INTL_COLLATOR_P(zv) php_intl_collator_fetch_object(Z_OBJ_P(zv))
+static zend_always_inline zend_result collator_check_initialized(Collator_object *co)
+{
+ ZEND_ASSERT(co != NULL);
+
+ if (UNEXPECTED(co->ucoll == NULL)) {
+ intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) );
+ intl_errors_set_custom_msg(COLLATOR_ERROR_P( co ), "Object not initialized");
+ zend_throw_error(NULL, "Object not initialized");
+
+ return FAILURE;
+ }
+
+ return SUCCESS;
+}
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/ext/intl/collator/collator_compare.cpp b/ext/intl/collator/collator_compare.cpp
index bac0bbf50b21..4bfe0956a3f7 100644
--- a/ext/intl/collator/collator_compare.cpp
+++ b/ext/intl/collator/collator_compare.cpp
@@ -55,11 +55,7 @@ U_CFUNC PHP_FUNCTION( collator_compare )
/* Fetch the object. */
COLLATOR_METHOD_FETCH_OBJECT;
- if (!co || !co->ucoll) {
- intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) );
- intl_errors_set_custom_msg(COLLATOR_ERROR_P( co ), "Object not initialized");
- zend_throw_error(NULL, "Object not initialized");
-
+ if (collator_check_initialized(co) == FAILURE) {
RETURN_THROWS();
}
diff --git a/ext/intl/collator/collator_locale.cpp b/ext/intl/collator/collator_locale.cpp
index ea1393779846..20aba988fb40 100644
--- a/ext/intl/collator/collator_locale.cpp
+++ b/ext/intl/collator/collator_locale.cpp
@@ -48,11 +48,7 @@ U_CFUNC PHP_FUNCTION( collator_get_locale )
/* Fetch the object. */
COLLATOR_METHOD_FETCH_OBJECT;
- if (!co || !co->ucoll) {
- intl_error_set_code( nullptr, COLLATOR_ERROR_CODE( co ) );
- intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ), "Object not initialized");
- zend_throw_error(nullptr, "Object not initialized");
-
+ if (collator_check_initialized(co) == FAILURE) {
RETURN_THROWS();
}
diff --git a/ext/intl/collator/collator_sort.cpp b/ext/intl/collator/collator_sort.cpp
index 3f2e1cf543d8..dc5898d23a6e 100644
--- a/ext/intl/collator/collator_sort.cpp
+++ b/ext/intl/collator/collator_sort.cpp
@@ -433,11 +433,7 @@ U_CFUNC PHP_FUNCTION( collator_sort_with_sort_keys )
/* Fetch the object. */
COLLATOR_METHOD_FETCH_OBJECT;
- if (!co || !co->ucoll) {
- intl_error_set_code( nullptr, COLLATOR_ERROR_CODE( co ) );
- intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ), "Object not initialized");
- zend_throw_error(NULL, "Object not initialized");
-
+ if (collator_check_initialized(co) == FAILURE) {
RETURN_THROWS();
}
@@ -598,11 +594,7 @@ U_CFUNC PHP_FUNCTION( collator_get_sort_key )
/* Fetch the object. */
COLLATOR_METHOD_FETCH_OBJECT;
- if (!co || !co->ucoll) {
- intl_error_set_code( nullptr, COLLATOR_ERROR_CODE( co ) );
- intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ), "Object not initialized");
- zend_throw_error(NULL, "Object not initialized");
-
+ if (collator_check_initialized(co) == FAILURE) {
RETURN_THROWS();
}
diff --git a/ext/intl/tests/collator_attribute_unconstructed.phpt
b/ext/intl/tests/collator_attribute_unconstructed.phpt
new file mode 100644
index 000000000000..f8eb5afa01d5
--- /dev/null
+++ b/ext/intl/tests/collator_attribute_unconstructed.phpt
@@ -0,0 +1,55 @@
+--TEST--
+Collator attribute and strength methods on unconstructed object
+--EXTENSIONS--
+intl
+--FILE--
+<?php
+
+class Collator2 extends Collator {
+ public function __construct() {
+ // omitting parent::__construct($someLocale);
+ }
+}
+
+$c = new Collator2();
+
+$methods = [
+ 'getAttribute' => fn() => $c->getAttribute(Collator::NUMERIC_COLLATION),
+ 'setAttribute' => fn() => $c->setAttribute(Collator::NUMERIC_COLLATION,
Collator::ON),
+ 'getStrength' => fn() => $c->getStrength(),
+ 'setStrength' => fn() => $c->setStrength(Collator::SECONDARY),
+];
+
+foreach ($methods as $method => $call) {
+ try {
+ $call();
+ } catch (Error $e) {
+ echo $method, ': ', $e::class, ': ', $e->getMessage(), PHP_EOL;
+ }
+}
+
+$functions = [
+ 'collator_get_attribute' => fn() => collator_get_attribute($c,
Collator::NUMERIC_COLLATION),
+ 'collator_set_attribute' => fn() => collator_set_attribute($c,
Collator::NUMERIC_COLLATION, Collator::ON),
+ 'collator_get_strength' => fn() => collator_get_strength($c),
+ 'collator_set_strength' => fn() => collator_set_strength($c,
Collator::SECONDARY),
+];
+
+foreach ($functions as $function => $call) {
+ try {
+ $call();
+ } catch (Error $e) {
+ echo $function, ': ', $e::class, ': ', $e->getMessage(), PHP_EOL;
+ }
+}
+
+?>
+--EXPECT--
+getAttribute: Error: Object not initialized
+setAttribute: Error: Object not initialized
+getStrength: Error: Object not initialized
+setStrength: Error: Object not initialized
+collator_get_attribute: Error: Object not initialized
+collator_set_attribute: Error: Object not initialized
+collator_get_strength: Error: Object not initialized
+collator_set_strength: Error: Object not initialized