@@ -336,18 +336,28 @@ public static function isComment($str, $end = false)
336336 if ($ len === 0 ) {
337337 return null ;
338338 }
339+
340+ // If comment is Bash style (#):
339341 if ($ str [0 ] === '# ' ) {
340342 return Token::FLAG_COMMENT_BASH ;
341- } elseif (($ len > 1 ) && ($ str [0 ] === '/ ' ) && ($ str [1 ] === '* ' )) {
342- return (($ len > 2 ) && ($ str [2 ] === '! ' )) ?
343+ }
344+ // If comment is opening C style (/*), warning, it could be a MySQL command (/*!)
345+ if (($ len > 1 ) && ($ str [0 ] === '/ ' ) && ($ str [1 ] === '* ' )) {
346+ return ($ len > 2 ) && ($ str [2 ] === '! ' ) ?
343347 Token::FLAG_COMMENT_MYSQL_CMD : Token::FLAG_COMMENT_C ;
344- } elseif (($ len > 1 ) && ($ str [0 ] === '* ' ) && ($ str [1 ] === '/ ' )) {
348+ }
349+ // If comment is closing C style (*/), warning, it could conflicts with wildcard and a real opening C style.
350+ // It would looks like the following valid SQL statement: "SELECT */* comment */ FROM...".
351+ if (($ len > 1 ) && ($ str [0 ] === '* ' ) && ($ str [1 ] === '/ ' )) {
345352 return Token::FLAG_COMMENT_C ;
346- } elseif (($ len > 2 ) && ($ str [0 ] === '- ' )
353+ }
354+ // If comment is SQL style (--\s?):
355+ if (($ len > 2 ) && ($ str [0 ] === '- ' )
347356 && ($ str [1 ] === '- ' ) && static ::isWhitespace ($ str [2 ])
348357 ) {
349358 return Token::FLAG_COMMENT_SQL ;
350- } elseif (($ len === 2 ) && $ end && ($ str [0 ] === '- ' ) && ($ str [1 ] === '- ' )) {
359+ }
360+ if (($ len === 2 ) && $ end && ($ str [0 ] === '- ' ) && ($ str [1 ] === '- ' )) {
351361 return Token::FLAG_COMMENT_SQL ;
352362 }
353363
0 commit comments