Skip to content

Commit ccd0745

Browse files
authored
Prevent Undefined offset error
For some reason the argument `$tokens` comes sometime as a numeric array starting with an index greater than 0. In this case the loop with `$tokenNumber` starting at 0 will not be able to read the token and will throw an error `Undefined offset`
1 parent c58ac6c commit ccd0745

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/PHPSQLParser/processors/SQLProcessor.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ public function process($tokens) {
6161
$skip_next = 0;
6262
$out = false;
6363

64-
$tokenCount = count($tokens);
64+
// $tokens may come as a numeric indexed array starting with an index greater than 0 (or as a boolean)
65+
if ( $tokenCount = count($tokens) ){
66+
$tokens = array_values($tokens);
67+
}
6568
for ($tokenNumber = 0; $tokenNumber < $tokenCount; ++$tokenNumber) {
6669

6770
$token = $tokens[$tokenNumber];

0 commit comments

Comments
 (0)