Skip to content

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

Open
LamentXU123 wants to merge 2 commits into
php:masterfrom
LamentXU123:bug-fix-19
Open

ext/Intl: Return PHP_INT_MIN as int from MessageFormatter::parse() on 64-bit#22131
LamentXU123 wants to merge 2 commits into
php:masterfrom
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.

Comment thread ext/intl/msgformat/msgformat_helpers.cpp
Comment thread ext/intl/tests/msgfmt_parse_int64_min_64.phpt Outdated
@LamentXU123 LamentXU123 marked this pull request as draft May 23, 2026 04:44
@devnexen
Copy link
Copy Markdown
Member

devnexen commented May 23, 2026

Anyhow, I ll look into it in your intl PRs in one swoop later.

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