Skip to content

ext/Intl: Return PHP_INT_MIN as int from MessageFormatter::parse() on 64-bit#22131

Open
LamentXU123 wants to merge 1 commit into
php:PHP-8.4from
LamentXU123:bug-fix-19
Open

ext/Intl: Return PHP_INT_MIN as int from MessageFormatter::parse() on 64-bit#22131
LamentXU123 wants to merge 1 commit into
php:PHP-8.4from
LamentXU123:bug-fix-19

Conversation

@LamentXU123
Copy link
Copy Markdown
Contributor

@LamentXU123 LamentXU123 commented May 22, 2026

Cleaning up. -ZEND_LONG_MAX does not equals to ZEND_LONG_MIN, because signed integer ranges are not symmetric
in 64-bit

-ZEND_LONG_MAX = -9223372036854775807
ZEND_LONG_MIN = -9223372036854775808

This makes -9,223,372,036,854,775,808 in MessageFormatter be degraded into float, but it could be an integer.

<?php

$fmt = new MessageFormatter('en_US', '{0,number,integer}');
$parsed = $fmt->parse('-9,223,372,036,854,775,808');
var_dump($parsed);

$parsed = MessageFormatter::parseMessage('en_US', '{0,number,integer}', '-9,223,372,036,854,775,808');
var_dump($parsed);

?>

result in

array(1) {
  [0]=>
  float(-9.223372036854776E+18)
}
array(1) {
  [0]=>
  float(-9.223372036854776E+18)
}

But it should be

array(1) {
  [0]=>
  int(-9223372036854775808)
}
array(1) {
  [0]=>
  int(-9223372036854775808)
}

Reproduce

This is really a super super edge case. I don't even sure we should treat this as a bug fix or a refactor at this point. It really do come into my mind when I am looking at this code that I don't even think we need any NEWS or UPGRADING entry for this little fix. No similar bugs in the code base.

case Formattable::kInt64:
aInt64 = fargs[i].getInt64();
if(aInt64 > ZEND_LONG_MAX || aInt64 < -ZEND_LONG_MAX) {
if(aInt64 > ZEND_LONG_MAX || aInt64 < ZEND_LONG_MIN) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's retarget this at master rather than PHP-8.4. It's a correctness fix, but the return type changes from float to int for PHP_INT_MIN, which is
user-observable, and I'd rather not ship that mid stable cycle for an edge case.

@@ -0,0 +1,26 @@
--TEST--
Bug: MessageFormatter::parse() should preserve PHP_INT_MIN as int on 64-bit
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong format for description. Anyhow there is an argument for making a 32 bit version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants