Re: [RFC] Normalize token_get_all() output (with flag)
| From: | Sara Golemon | Date: | Tue, 05 Jan 2016 19:51:58 +0000 |
| Subject: | Re: [RFC] Normalize token_get_all() output (with flag) | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-90142@lists.php.net to get a copy of this message | ||
On Mon, Jan 4, 2016 at 2:56 PM, Sara Golemon <pollita@php.net> wrote:
> https://wiki.php.net/rfc/token-get-always-tokens
>
A suggestion from a co-worker who's worried about seeing patterns like:
case ($t['token']) {
case T_PAAMAYIM_NEKUDOTAYIM:
// do something
break;
case ord(';'):
// do something else
break;
}
I see three options to remediate this:
1) We could offer constants like: T_SEMICOLON (or T_ASCII_SEMICOLON)
defined to that character's ordinal value. (using unicode names)
2) Make the token field be the character value (for single-character
tokens) instead of the ordinal.
3) Add an additional field such that you have Array ( ['id'] => 59,
['token'] => ';', ['text'] => ';', ['line']
=> 1 ) 'id' would always
be integer, while 'token' would be int or single-char.
I don't like 3 as it's wasteful and needlessly duplicative. 1 feels a
bit over-engineered and actually hurts readability. 2 feels like a
nice compromise and matches how our rules end up looking in the parser
anyway (since C treats single characters as ordinals already).
-Sara