Skip to content

Commit edde169

Browse files
committed
ext/intl: Guard Spoofchecker restriction-level APIs at ICU 53
PHP-8.4 still supports ICU 50.1+, but GH-22055 removed the version guard around the Spoofchecker restriction-level API and made builds fail on ICU 50.x. Restore the guard at ICU 53 so the API remains available where supported without breaking older supported ICU versions. Closes GH-22248.
1 parent 43838c4 commit edde169

7 files changed

Lines changed: 43 additions & 1 deletion

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ PHP NEWS
2020
. Fix incorrect argument positions for uninitialized calendar arguments in
2121
IntlCalendar::equals(), ::before(), ::after(), and ::isEquivalentTo().
2222
(Weilin Du)
23+
. Fixed Spoofchecker restriction-level APIs to only be exposed with ICU 53
24+
and later. (Graham Campbell)
2325

2426
- mysqli:
2527
. Fix stmt->query leak in mysqli_execute_query() validation errors.

ext/intl/spoofchecker/spoofchecker.stub.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Spoofchecker
1919
public const int INVISIBLE = UNKNOWN;
2020
/** @cvalue USPOOF_CHAR_LIMIT */
2121
public const int CHAR_LIMIT = UNKNOWN;
22+
#if U_ICU_VERSION_MAJOR_NUM >= 53
2223
/** @cvalue USPOOF_ASCII */
2324
public const int ASCII = UNKNOWN;
2425
/** @cvalue USPOOF_HIGHLY_RESTRICTIVE */
@@ -33,6 +34,7 @@ class Spoofchecker
3334
public const int SINGLE_SCRIPT_RESTRICTIVE = UNKNOWN;
3435
/** @cvalue USPOOF_MIXED_NUMBERS */
3536
public const int MIXED_NUMBERS = UNKNOWN;
37+
#endif
3638
#if U_ICU_VERSION_MAJOR_NUM >= 62
3739
/** @cvalue USPOOF_HIDDEN_OVERLAY */
3840
public const int HIDDEN_OVERLAY = UNKNOWN;
@@ -69,7 +71,9 @@ public function setAllowedLocales(string $locales): void {}
6971
/** @tentative-return-type */
7072
public function setChecks(int $checks): void {}
7173

74+
#if U_ICU_VERSION_MAJOR_NUM >= 53
7275
/** @tentative-return-type */
7376
public function setRestrictionLevel(int $level): void {}
77+
#endif
7478
public function setAllowedChars(string $pattern, int $patternOptions = 0): void {}
7579
}

ext/intl/spoofchecker/spoofchecker_arginfo.h

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/intl/spoofchecker/spoofchecker_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ PHP_METHOD(Spoofchecker, setChecks)
135135
}
136136
/* }}} */
137137

138+
#if U_ICU_VERSION_MAJOR_NUM >= 53
138139
/* TODO Document this method on PHP.net */
139140
/* {{{ Set the loosest restriction level allowed for strings. */
140141
PHP_METHOD(Spoofchecker, setRestrictionLevel)
@@ -163,6 +164,7 @@ PHP_METHOD(Spoofchecker, setRestrictionLevel)
163164
uspoof_setRestrictionLevel(co->uspoof, (URestrictionLevel)level);
164165
}
165166
/* }}} */
167+
#endif
166168

167169
PHP_METHOD(Spoofchecker, setAllowedChars)
168170
{

ext/intl/tests/spoofchecker_007.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ spoofchecker with restriction level
44
intl
55
--SKIPIF--
66
<?php if(!class_exists("Spoofchecker")) print 'skip'; ?>
7+
<?php
8+
$r = new ReflectionClass("SpoofChecker");
9+
if (false === $r->getConstant("SINGLE_SCRIPT_RESTRICTIVE")) {
10+
die("skip for ICU version < 53");
11+
}
12+
?>
713
--FILE--
814
<?php
915

ext/intl/tests/spoofchecker_supported_icu57_apis.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Spoofchecker exposes restriction-level APIs on all supported ICU versions
44
intl
55
--SKIPIF--
66
<?php if (!class_exists("Spoofchecker")) print 'skip'; ?>
7+
<?php
8+
$r = new ReflectionClass("Spoofchecker");
9+
if (false === $r->getConstant("SINGLE_SCRIPT_RESTRICTIVE")) {
10+
die("skip for ICU version < 53");
11+
}
12+
?>
713
--FILE--
814
<?php
915
$r = new ReflectionClass("Spoofchecker");

ext/intl/tests/spoofchecker_unknown_restriction_level.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ intl
55
--SKIPIF--
66
<?php
77
if (!class_exists("Spoofchecker")) print 'skip';
8+
9+
if (!method_exists(new Spoofchecker(), 'setRestrictionLevel')) print 'skip for ICU version < 53';
810
?>
911
--FILE--
1012
<?php

0 commit comments

Comments
 (0)