Re: Re: [RFC] Normalize token_get_all() output (with flag)

From: Date: Sun, 10 Jan 2016 21:31:22 +0000
Subject: Re: Re: [RFC] Normalize token_get_all() output (with flag)
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-90463@lists.php.net to get a copy of this message
Hi! >> 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; >> } What's wrong with this pattern? Looks pretty fine to me, clear what's going on. >> 2) Make the token field be the character value (for single-character >> tokens) instead of the ordinal. That would work too, but the side effect would be mixing types. It probably not too much trouble since tokens are numbered > 255, but it may have some unexpected effects that most of the tokens would match by == 0. Not sure if that's a problem. >> 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 Agree on both 1 and 3. -- Stas Malyshev smalyshev@gmail.com

« previous php.internals (#90463) next »