Skip to content

Commit 58b2e59

Browse files
committed
Tokenizer / numeric separators backfill: fix incorrect token types
When the final content of a numeric token is more than PHP_INT_MAX or when a numeric token contains a `.` or an `E/e`, it should be tokenized as `T_DNUMBER`. This fixes the first set of the unit test failures.
1 parent f80915e commit 58b2e59

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/Tokenizers/PHP.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -997,12 +997,6 @@ protected function tokenize($string)
997997
) {
998998
$newContent .= $tokens[$i][1];
999999

1000-
// Any T_DNUMBER token needs to make the
1001-
// new number a T_DNUMBER as well.
1002-
if ($tokens[$i][0] === T_DNUMBER) {
1003-
$newType = T_DNUMBER;
1004-
}
1005-
10061000
// Support floats.
10071001
if ($tokens[$i][0] === T_STRING
10081002
&& substr(strtolower($tokens[$i][1]), -1) === 'e'
@@ -1019,9 +1013,21 @@ protected function tokenize($string)
10191013
break;
10201014
}//end for
10211015

1016+
if ($newType === T_LNUMBER
1017+
&& ((stripos($newContent, '0x') === 0 && hexdec(str_replace('_', '', $newContent)) > PHP_INT_MAX)
1018+
|| (stripos($newContent, '0b') === 0 && bindec(str_replace('_', '', $newContent)) > PHP_INT_MAX)
1019+
|| (stripos($newContent, '0x') !== 0
1020+
&& stripos($newContent, 'e') !== false || strpos($newContent, '.') !== false)
1021+
|| (strpos($newContent, '0') === 0 && stripos($newContent, '0x') !== 0
1022+
&& stripos($newContent, '0b') !== 0 && octdec(str_replace('_', '', $newContent)) > PHP_INT_MAX)
1023+
|| (strpos($newContent, '0') !== 0 && str_replace('_', '', $newContent) > PHP_INT_MAX))
1024+
) {
1025+
$newType = T_DNUMBER;
1026+
}
1027+
10221028
$newToken = [];
10231029
$newToken['code'] = $newType;
1024-
$newToken['type'] = Util\Tokens::tokenName($token[0]);
1030+
$newToken['type'] = Util\Tokens::tokenName($newType);
10251031
$newToken['content'] = $newContent;
10261032
$finalTokens[$newStackPtr] = $newToken;
10271033

0 commit comments

Comments
 (0)