Repository navigation
Normalize integer literals to decimal - #348
Merged
Merged
Conversation
ConstExprIntegerNode::$value kept the spelling of the literal, so casting it with (int) read 0x1F, 0b101 and 0o17 as 0 and the legacy octal 017 as 17. The parser now stores the decimal number the literal denotes, of any size, so 0x1F is '31' and +123 is '123'. Amp-Thread-ID: https://ampcode.com/threads/T-01a1eeb7-0373-7460-8310-e6c03050dc58
ondrejmirtes
force-pushed
the
integer-literal-numeric-value
branch
from
November 25, 2026 13:05
3fe1408 to
0cef6a9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ConstExprIntegerNode::$valuekept the spelling of the literal, so consumers that cast it with(int)read0x1F,0b101and0o17as0and the legacy octal017as17. In PHPStan,@param 0x1F $xresolved to0,int<0, 0xFF>to0, andarray{0x10: int}toarray{0: int}.The parser now stores the decimal number the literal denotes:
0x1F→'31',017and0o17→'15',-0b11→'-3',+123→'123'. This covers binary, octal (0oand a leading0, like PHP), hexadecimal, signs and underscores, in any case. Numbers of any size are converted exactly, as strings, so a value beyondPHP_INT_MAXbehaves like a decimal literal of that size did before.The existing
(int)casts in consumers then work as they are. Printing a node that came from a non-decimal literal now gives the decimal form.