Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested ternary operators not tokenized correctly #342

Closed
loonies opened this issue Dec 7, 2014 · 1 comment
Closed

Nested ternary operators not tokenized correctly #342

loonies opened this issue Dec 7, 2014 · 1 comment

Comments

@loonies
Copy link
Contributor

loonies commented Dec 7, 2014

In the following piece of code

$foo = $bar ? ($baz ? $baz : false) : $foobar;

the last colon ($token[21]) will be tokenized as T_COLON. I was
expecting T_INLINE_ELSE instead. Is this intentional?

I've also found this issue #333, which is maybe related.

Tested with the latest 1.x and 2.x.

Tokenized code:

$tokens[1]['type'] = T_VARIABLE
$tokens[2]['type'] = T_WHITESPACE
$tokens[3]['type'] = T_EQUAL
$tokens[4]['type'] = T_WHITESPACE
$tokens[5]['type'] = T_VARIABLE
$tokens[6]['type'] = T_WHITESPACE
$tokens[7]['type'] = T_INLINE_THEN
$tokens[8]['type'] = T_WHITESPACE
$tokens[9]['type'] = T_OPEN_PARENTHESIS
$tokens[10]['type'] = T_VARIABLE
$tokens[11]['type'] = T_WHITESPACE
$tokens[12]['type'] = T_INLINE_THEN
$tokens[13]['type'] = T_WHITESPACE
$tokens[14]['type'] = T_VARIABLE
$tokens[15]['type'] = T_WHITESPACE
$tokens[16]['type'] = T_INLINE_ELSE
$tokens[17]['type'] = T_WHITESPACE
$tokens[18]['type'] = T_FALSE
$tokens[19]['type'] = T_CLOSE_PARENTHESIS
$tokens[20]['type'] = T_WHITESPACE
$tokens[21]['type'] = T_COLON
$tokens[22]['type'] = T_WHITESPACE
$tokens[23]['type'] = T_VARIABLE
$tokens[24]['type'] = T_SEMICOLON
$tokens[25]['type'] = T_WHITESPACE
@gsherwood gsherwood changed the title Nested ternary operators causing problems #2 Nested ternary operators not tokenized correctly Dec 7, 2014
@gsherwood
Copy link
Member

Turned out to be unrelated to #333. It was caused by the tokenizer assuming one level of ternary operators. I changed it to a stack and it is tokenizing correctly now.

Thanks for the really clear bug report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants