Bug->Doc #71207 [Nab->Opn]: token_get_all does not recognize context-sensitive keywords

From: Date: Wed, 23 Dec 2015 22:38:09 +0000
Subject: Bug->Doc #71207 [Nab->Opn]: token_get_all does not recognize context-sensitive keywords
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-13028@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71207&edit=1 ID: 71207 Updated by: nikic@php.net Reported by: kontakt at kukulich dot cz Summary: token_get_all does not recognize context-sensitive keywords -Status: Not a bug +Status: Open -Type: Bug +Type: Documentation Problem Package: Unknown/Other Function PHP Version: 7.0.1 Block user comment: N Private report: N New Comment: Switching to doc bug as the new parameter seems to be undocumented. Previous Comments: ------------------------------------------------------------------------ [2015-12-23 22:37:29] nikic@php.net If you want these to be recognized, you must pass the TOKEN_PARSE flag as the second argument to token_get_all(). ------------------------------------------------------------------------ [2015-12-23 22:33:21] kontakt at kukulich dot cz Description: ------------ Thanks to https://wiki.php.net/rfc/context_sensitive_lexer it's possible in PHP7 to use a lot of keywords as constants, methods etc. However token_get_all doesn't return the right tokens. Test script: --------------- <?php $tokens = token_get_all('<?php class Test {const PUBLIC=0;}'); foreach ($tokens as $token) { if (is_array($token)) { echo token_name($token[0]) . "\n"; } } Expected result: ---------------- T_OPEN_TAG T_CLASS T_WHITESPACE T_STRING T_WHITESPACE T_CONST T_WHITESPACE T_STRING T_LNUMBER Actual result: -------------- T_OPEN_TAG T_CLASS T_WHITESPACE T_STRING T_WHITESPACE T_CONST T_WHITESPACE T_PUBLIC T_LNUMBER ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71207&edit=1

« previous php.doc.bugs (#13028) next »