|
1 | 1 | --TEST-- |
2 | | -Collator::sort() conversion failure must survive a re-entrant Collator call |
| 2 | +Collator::sort() conversion failure must survive a re-entrant Collator call in __toString() |
3 | 3 | --EXTENSIONS-- |
4 | 4 | intl |
5 | 5 | --FILE-- |
6 | 6 | <?php |
7 | | -class Bad { |
8 | | - public function __toString(): string { |
9 | | - return "\xFF"; |
10 | | - } |
11 | | -} |
12 | | - |
13 | | -class Toucher { |
| 7 | +class BadAfterReentry { |
14 | 8 | public static Collator $coll; |
| 9 | + public static bool $called = false; |
15 | 10 |
|
16 | 11 | public function __toString(): string { |
17 | | - if (self::$coll->getErrorCode() !== U_ZERO_ERROR) { |
18 | | - self::$coll->getLocale(Locale::VALID_LOCALE); |
19 | | - } |
20 | | - return 'z'; |
| 12 | + self::$called = true; |
| 13 | + self::$coll->getLocale(Locale::VALID_LOCALE); |
| 14 | + return "\xFF"; |
21 | 15 | } |
22 | 16 | } |
23 | 17 |
|
24 | 18 | $coll = new Collator('en_US'); |
25 | | -Toucher::$coll = $coll; |
| 19 | +BadAfterReentry::$coll = $coll; |
26 | 20 |
|
27 | | -$array = ['a', new Bad(), 'b', new Toucher()]; |
| 21 | +$array = ['a', new BadAfterReentry(), 'b']; |
28 | 22 |
|
29 | 23 | var_dump($coll->sort($array, Collator::SORT_STRING)); |
| 24 | +var_dump(BadAfterReentry::$called); |
30 | 25 | var_dump($coll->getErrorCode() === U_INVALID_CHAR_FOUND); |
31 | 26 | echo $coll->getErrorMessage(), PHP_EOL; |
32 | | -var_dump($array[0], $array[1] instanceof Bad, $array[2], $array[3] instanceof Toucher); |
| 27 | +var_dump($array[0], $array[1] instanceof BadAfterReentry, $array[2]); |
33 | 28 | ?> |
34 | 29 | --EXPECT-- |
35 | 30 | bool(false) |
36 | 31 | bool(true) |
| 32 | +bool(true) |
37 | 33 | Collator::sort(): Error converting string from UTF-8 to UTF-16: U_INVALID_CHAR_FOUND |
38 | 34 | string(1) "a" |
39 | 35 | bool(true) |
40 | 36 | string(1) "b" |
41 | | -bool(true) |
0 commit comments