Commit 438ad64407e for php.net
commit 438ad64407ec131d2f54930d499e897cf439f623
Author: “LamentXU123” <108666168+LamentXU123@users.noreply.github.com>
Date: Sat May 16 00:33:14 2026 +0800
ext/intl: Expose Spoofchecker restriction-level APIs on all supported ICU versions
Also fix the constant names referenced in the Spoofchecker::setAllowedChars()
error message (CASE_INSENSITIVE / ADD_CASE_MAPPINGS / SIMPLE_CASE_INSENSITIVE
rather than their USET_-prefixed counterparts).
Fix #22053
close GH-22055
diff --git a/ext/intl/spoofchecker/spoofchecker.stub.php b/ext/intl/spoofchecker/spoofchecker.stub.php
index 0141252d478..51a9c7d3907 100644
--- a/ext/intl/spoofchecker/spoofchecker.stub.php
+++ b/ext/intl/spoofchecker/spoofchecker.stub.php
@@ -19,7 +19,6 @@ class Spoofchecker
public const int INVISIBLE = UNKNOWN;
/** @cvalue USPOOF_CHAR_LIMIT */
public const int CHAR_LIMIT = UNKNOWN;
-#if U_ICU_VERSION_MAJOR_NUM >= 58
/** @cvalue USPOOF_ASCII */
public const int ASCII = UNKNOWN;
/** @cvalue USPOOF_HIGHLY_RESTRICTIVE */
@@ -34,7 +33,6 @@ class Spoofchecker
public const int SINGLE_SCRIPT_RESTRICTIVE = UNKNOWN;
/** @cvalue USPOOF_MIXED_NUMBERS */
public const int MIXED_NUMBERS = UNKNOWN;
-#endif
#if U_ICU_VERSION_MAJOR_NUM >= 62
/** @cvalue USPOOF_HIDDEN_OVERLAY */
public const int HIDDEN_OVERLAY = UNKNOWN;
@@ -71,9 +69,7 @@ public function setAllowedLocales(string $locales): void {}
/** @tentative-return-type */
public function setChecks(int $checks): void {}
-#if U_ICU_VERSION_MAJOR_NUM >= 58
/** @tentative-return-type */
public function setRestrictionLevel(int $level): void {}
-#endif
public function setAllowedChars(string $pattern, int $patternOptions = 0): void {}
}
diff --git a/ext/intl/spoofchecker/spoofchecker_arginfo.h b/ext/intl/spoofchecker/spoofchecker_arginfo.h
index 53679891442..8704065e479 100644
Binary files a/ext/intl/spoofchecker/spoofchecker_arginfo.h and b/ext/intl/spoofchecker/spoofchecker_arginfo.h differ
diff --git a/ext/intl/spoofchecker/spoofchecker_main.cpp b/ext/intl/spoofchecker/spoofchecker_main.cpp
index e3e21ef72b7..a4cb0b9fc64 100644
--- a/ext/intl/spoofchecker/spoofchecker_main.cpp
+++ b/ext/intl/spoofchecker/spoofchecker_main.cpp
@@ -142,7 +142,6 @@ U_CFUNC PHP_METHOD(Spoofchecker, setChecks)
}
/* }}} */
-#if U_ICU_VERSION_MAJOR_NUM >= 58
/* {{{ Set the loosest restriction level allowed for strings. */
U_CFUNC PHP_METHOD(Spoofchecker, setRestrictionLevel)
{
@@ -170,7 +169,6 @@ U_CFUNC PHP_METHOD(Spoofchecker, setRestrictionLevel)
uspoof_setRestrictionLevel(co->uspoof, (URestrictionLevel)level);
}
/* }}} */
-#endif
U_CFUNC PHP_METHOD(Spoofchecker, setAllowedChars)
{
@@ -214,9 +212,9 @@ U_CFUNC PHP_METHOD(Spoofchecker, setAllowedChars)
#endif
pattern_option != (USET_IGNORE_SPACE|USET_CASE_INSENSITIVE) &&
pattern_option != (USET_IGNORE_SPACE|USET_ADD_CASE_MAPPINGS)) {
- zend_argument_value_error(2, "must be a valid pattern option, 0 or (SpoofChecker::IGNORE_SPACE|(<none> or SpoofChecker::USET_CASE_INSENSITIVE or SpoofChecker::USET_ADD_CASE_MAPPINGS"
+ zend_argument_value_error(2, "must be a valid pattern option, 0 or (SpoofChecker::IGNORE_SPACE|(<none> or SpoofChecker::CASE_INSENSITIVE or SpoofChecker::ADD_CASE_MAPPINGS"
#if U_ICU_VERSION_MAJOR_NUM >= 73
- " or SpoofChecker::USET_SIMPLE_CASE_INSENSITIVE"
+ " or SpoofChecker::SIMPLE_CASE_INSENSITIVE"
#endif
"))"
);
diff --git a/ext/intl/tests/spoofchecker_007.phpt b/ext/intl/tests/spoofchecker_007.phpt
index b5fc5814ddf..5f3dbb47f19 100644
--- a/ext/intl/tests/spoofchecker_007.phpt
+++ b/ext/intl/tests/spoofchecker_007.phpt
@@ -4,12 +4,6 @@
intl
--SKIPIF--
<?php if(!class_exists("Spoofchecker")) print 'skip'; ?>
-<?php
- $r = new ReflectionClass("SpoofChecker");
- if (false === $r->getConstant("SINGLE_SCRIPT_RESTRICTIVE")) {
- die("skip Incompatible ICU version");
- }
-?>
--FILE--
<?php
diff --git a/ext/intl/tests/spoofchecker_008.phpt b/ext/intl/tests/spoofchecker_008.phpt
index 4eb78711c2c..66e39967c78 100644
--- a/ext/intl/tests/spoofchecker_008.phpt
+++ b/ext/intl/tests/spoofchecker_008.phpt
@@ -39,6 +39,6 @@
bool(true)
bool(false)
bool(false)
-Spoofchecker::setAllowedChars(): Argument #2 ($patternOptions) must be a valid pattern option, 0 or (SpoofChecker::IGNORE_SPACE|(<none> or SpoofChecker::USET_CASE_INSENSITIVE%s))
+Spoofchecker::setAllowedChars(): Argument #2 ($patternOptions) must be a valid pattern option, 0 or (SpoofChecker::IGNORE_SPACE|(<none> or SpoofChecker::CASE_INSENSITIVE%s))
Spoofchecker::setAllowedChars(): Argument #1 ($pattern) must be a valid regular expression character set pattern
Spoofchecker::setAllowedChars(): Argument #1 ($pattern) must be a valid regular expression character set pattern
diff --git a/ext/intl/tests/spoofchecker_supported_icu57_apis.phpt b/ext/intl/tests/spoofchecker_supported_icu57_apis.phpt
new file mode 100644
index 00000000000..56cc194991e
--- /dev/null
+++ b/ext/intl/tests/spoofchecker_supported_icu57_apis.phpt
@@ -0,0 +1,36 @@
+--TEST--
+Spoofchecker exposes restriction-level APIs on all supported ICU versions
+--EXTENSIONS--
+intl
+--SKIPIF--
+<?php if (!class_exists("Spoofchecker")) print 'skip'; ?>
+--FILE--
+<?php
+$r = new ReflectionClass("Spoofchecker");
+
+$ascii = $r->getConstant("ASCII");
+$singleScriptRestrictive = $r->getConstant("SINGLE_SCRIPT_RESTRICTIVE");
+$mixedNumbers = $r->getConstant("MIXED_NUMBERS");
+
+var_dump($ascii !== false);
+var_dump($singleScriptRestrictive !== false);
+var_dump($mixedNumbers !== false);
+var_dump(is_int($ascii));
+var_dump(is_int($singleScriptRestrictive));
+var_dump(is_int($mixedNumbers));
+var_dump($ascii !== $singleScriptRestrictive);
+var_dump($ascii !== $mixedNumbers);
+var_dump($singleScriptRestrictive !== $mixedNumbers);
+var_dump($r->hasMethod("setRestrictionLevel"));
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
diff --git a/ext/intl/tests/spoofchecker_unknown_restriction_level.phpt b/ext/intl/tests/spoofchecker_unknown_restriction_level.phpt
index 6b7e9474755..187be350f59 100644
--- a/ext/intl/tests/spoofchecker_unknown_restriction_level.phpt
+++ b/ext/intl/tests/spoofchecker_unknown_restriction_level.phpt
@@ -5,8 +5,6 @@
--SKIPIF--
<?php
if (!class_exists("Spoofchecker")) print 'skip';
-
-if (!method_exists(new Spoofchecker(), 'setRestrictionLevel')) print 'skip ICU version < 58';
?>
--FILE--
<?php