@@ -159,9 +159,24 @@ protected function handleErrors() {
159
159
$ line += substr_count ($ tokenValue , "\n" );
160
160
}
161
161
162
- // Invalid characters at the end of the input
163
162
if ($ filePos !== \strlen ($ this ->code )) {
164
- $ this ->handleInvalidCharacterRange ($ filePos , \strlen ($ this ->code ), $ line );
163
+ if (substr ($ this ->code , $ filePos , 2 ) === '/* ' ) {
164
+ // Unlike PHP, HHVM will drop unterminated comments entirely
165
+ $ comment = substr ($ this ->code , $ filePos );
166
+ $ this ->errors [] = new Error ('Unterminated comment ' , [
167
+ 'startLine ' => $ line ,
168
+ 'endLine ' => $ line + substr_count ($ comment , "\n" ),
169
+ 'startFilePos ' => $ filePos ,
170
+ 'endFilePos ' => $ filePos + \strlen ($ comment ),
171
+ ]);
172
+
173
+ // Emulate the PHP behavior
174
+ $ isDocComment = isset ($ comment [3 ]) && $ comment [3 ] === '* ' ;
175
+ $ this ->tokens [] = [$ isDocComment ? T_DOC_COMMENT : T_COMMENT , $ comment , $ line ];
176
+ } else {
177
+ // Invalid characters at the end of the input
178
+ $ this ->handleInvalidCharacterRange ($ filePos , \strlen ($ this ->code ), $ line );
179
+ }
165
180
}
166
181
167
182
// Check for unterminated comment
0 commit comments