[php-src] PR #22533: ext/Intl: Fix IntlDateFormatter offset type validation
| From: | LamentXU123 | Date: | Wed, 01 Jul 2026 12:52:50 +0000 |
| Subject: | [php-src] PR #22533: ext/Intl: Fix IntlDateFormatter offset type validation | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-36757@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/22533
Author: LamentXU123
Now in
IntlDateFormatter::parseToCalendar we verify if the offset is a int
```
<?php
$fmt = new IntlDateFormatter('en_GB');
$fmt->setPattern('VV');
$offset = 'offset';
try {
$fmt->parseToCalendar('America/Los_Angeles', $offset);
} catch (TypeError $e) {
echo $e->getMessage(), PHP_EOL;
}
```
```
IntlDateFormatter::parseToCalendar(): Argument #2 ($offset) must be of type int, string given
```
reproduce
[here](https://onlinephp.io?s=RY3dCoJAEIXvg95hLoRdQekBKsPKfsDIC_FWFhs10F3ZHQiJ3r1Vk-bqMN_hO7DZdXW3XAA4ZUuwBYkvuEpqjoLwpHQriFBzhjI_75m7npt-YJCSEUrOsmxEI1RlaZE1sSmxHyDdw3sIw02KTmiDqTqIBuVD2JWwRf0sxCpWJg9lhQ0a5s3KafwDhaCiBp72HUZaKw0Oun8zFrWyHz-okG5ojKiQux4klySP7vGk-AI%2C&v=8.5.6)
However, in IntlDateFormatter::parse() and IntlDateFormatter::localtime()
we silently accept offset that is not a int and turns it into 0
```
<?php
$fmt = new IntlDateFormatter('en_GB');
$fmt->setPattern('VV');
$offset = 'offset';
$fmt->parse('America/Los_Angeles', $offset);
$fmt->localtime('America/Los_Angeles', $offset);
```
This will not throws an error, reproduce
[here](https://onlinephp.io?s=s7EvyCjg5VJQUEnLLVGwVchLLVfwzCvJcUksSXXLL8pNLClJLdJQT82Ld3dS17SGqdS1K04tCQBL5mmoh4WBpcCS-WlpQCmgSeoQljqSnoLEouJUDXXH3NSizOREfZ_84njHvPTUnNRidR2YTmQ7cvKTE3NKMnMJ6wEA&v=8.5.6)
At least for consistence's sake, we should reject non-int offset in these
functions (This also aligns with previous fixes about avoiding silently casting).