|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2018-06-09 11:26 UTC] nathanielzimmermann at gmail dot com
Description:
------------
token_get_all with the TOKEN_PARSE flag fails to recognise the T_CLOSE_TAG token
Test script:
---------------
<?php
var_dump(token_get_all('<?php echo 1; ?>', TOKEN_PARSE)[6]);
Expected result:
----------------
array(3) {
[0]=>
int(381)
[1]=>
string(2) "?>"
[2]=>
int(1)
}
Actual result:
--------------
string(2) "?>"
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 05:00:01 2025 UTC |
I am afraid that the special cases should be handled in tokenizer side now :< diff --git a/ext/tokenizer/tokenizer.c b/ext/tokenizer/tokenizer.c index ef9d136..9524c69 100644 --- a/ext/tokenizer/tokenizer.c +++ b/ext/tokenizer/tokenizer.c @@ -191,8 +191,16 @@ void on_event(zend_php_scanner_event event, int token, int line, void *context) switch (event) { case ON_TOKEN: - if (token == END) break; - add_token(token_stream, token, LANG_SCNG(yy_text), LANG_SCNG(yy_leng), line); + { + if (token == END) break; + /* Specical cases */ + if (token == ';' && LANG_SCNG(yy_leng) == 2) { + token = T_CLOSE_TAG; + } else if (token == T_ECHO && LANG_SCNG(yy_leng) == 3) { + token = T_OPEN_TAG_WITH_ECHO; + } + add_token(token_stream, token, LANG_SCNG(yy_text), LANG_SCNG(yy_leng), line); + } break; case ON_FEEDBACK: tokens_ht = Z_ARRVAL_P(token_stream);Thanks! A small improvement might be to replace the integer literals with sizeof("?>")-1 and sizeof("<?=")-1, respectively.