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
smalys...@gmail.com

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to