Skip to content

Commit 8ada8fc

Browse files
author
MarkBaker
committed
Tokenizer code changes for converting an explicit PHP 8.1 octal reference (e.g."0o777") from two separate T_NUMBER and T_STRING tokens into a single T_NUMBER token with the correct value
1 parent 2a3eef6 commit 8ada8fc

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/Tokenizers/PHP.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,23 @@ protected function tokenize($string)
553553
$lastNotEmptyToken = ($newStackPtr - 1);
554554
}
555555

556+
/*
557+
For Explicit Octal Notation prior to PHP 8.1 we need to combine the
558+
T_NUMBER and T_STRING token values into a single token value, and
559+
then ignore the T_STRING token.
560+
*/
561+
562+
if (PHP_VERSION_ID < 80100
563+
&& $tokenIsArray === true && $token[1] === '0'
564+
&& (isset($tokens[($stackPtr + 1)]) === true
565+
&& is_array($tokens[($stackPtr + 1)]) === true
566+
&& $tokens[($stackPtr + 1)][0] === T_STRING
567+
&& $tokens[($stackPtr + 1)][1][0] === 'o')
568+
) {
569+
$token[1] .= $tokens[($stackPtr + 1)][1];
570+
$tokens[($stackPtr + 1)] = '';
571+
}
572+
556573
/*
557574
If we are using \r\n newline characters, the \r and \n are sometimes
558575
split over two tokens. This normally occurs after comments. We need
@@ -1330,6 +1347,7 @@ protected function tokenize($string)
13301347
if ($newType === T_LNUMBER
13311348
&& ((stripos($newContent, '0x') === 0 && hexdec(str_replace('_', '', $newContent)) > PHP_INT_MAX)
13321349
|| (stripos($newContent, '0b') === 0 && bindec(str_replace('_', '', $newContent)) > PHP_INT_MAX)
1350+
|| (stripos($newContent, '0o') === 0 && octdec(str_replace('_', '', $newContent)) > PHP_INT_MAX)
13331351
|| (stripos($newContent, '0x') !== 0
13341352
&& stripos($newContent, 'e') !== false || strpos($newContent, '.') !== false)
13351353
|| (strpos($newContent, '0') === 0 && stripos($newContent, '0x') !== 0

0 commit comments

Comments
 (0)