You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, when using such a ternary in a function declaration for the default value:
The ? gets misidentified as T_NULLABLE while I would expect it to be T_INLINE_THEN
The : gets misidentified as T_COLON while I would expect it to be T_INLINE_ELSE
Test code:
functionfoo($c = ((BAR)?10:100)) {}
Debug output:
*** START LEVEL MAP ***
Process token 0 on line 1 [col:1;len:5;lvl:0;]: T_OPEN_TAG => <?php\n
Process token 1 on line 2 [col:1;len:0;lvl:0;]: T_WHITESPACE => \n
Process token 2 on line 3 [col:1;len:8;lvl:0;]: T_FUNCTION => function
Process token 3 on line 3 [col:9;len:1;lvl:0;]: T_WHITESPACE =>
Process token 4 on line 3 [col:10;len:3;lvl:0;]: T_STRING => foo
Process token 5 on line 3 [col:13;len:1;lvl:0;]: T_OPEN_PARENTHESIS => (
Process token 6 on line 3 [col:14;len:2;lvl:0;]: T_VARIABLE => $c
Process token 7 on line 3 [col:16;len:1;lvl:0;]: T_WHITESPACE =>
Process token 8 on line 3 [col:17;len:1;lvl:0;]: T_EQUAL => =
Process token 9 on line 3 [col:18;len:1;lvl:0;]: T_WHITESPACE =>
Process token 10 on line 3 [col:19;len:1;lvl:0;]: T_OPEN_PARENTHESIS => (
Process token 11 on line 3 [col:20;len:1;lvl:0;]: T_OPEN_PARENTHESIS => (
Process token 12 on line 3 [col:21;len:3;lvl:0;]: T_STRING => BAR
Process token 13 on line 3 [col:24;len:1;lvl:0;]: T_CLOSE_PARENTHESIS => )
Process token 14 on line 3 [col:25;len:1;lvl:0;]: T_NULLABLE => ?
Process token 15 on line 3 [col:26;len:2;lvl:0;]: T_LNUMBER => 10
Process token 16 on line 3 [col:28;len:1;lvl:0;]: T_COLON => :
Process token 17 on line 3 [col:29;len:3;lvl:0;]: T_LNUMBER => 100
Process token 18 on line 3 [col:32;len:1;lvl:0;]: T_CLOSE_PARENTHESIS => )
Process token 19 on line 3 [col:33;len:1;lvl:0;]: T_CLOSE_PARENTHESIS => )
Process token 20 on line 3 [col:34;len:1;lvl:0;]: T_WHITESPACE =>
Process token 21 on line 3 [col:35;len:1;lvl:0;]: T_OPEN_CURLY_BRACKET => {
=> Found scope opener for 2:T_FUNCTION
* level increased *
* token 2:T_FUNCTION added to conditions array *
Process token 22 on line 3 [col:36;len:1;lvl:1;conds;T_FUNCTION;]: T_CLOSE_CURLY_BRA
CKET => }
=> Found scope closer for 21:T_OPEN_CURLY_BRACKET
* token T_FUNCTION removed from conditions array *
* level decreased *
Process token 23 on line 3 [col:37;len:0;lvl:0;]: T_WHITESPACE => \n
*** END LEVEL MAP ***
*** START ADDITIONAL PHP PROCESSING ***
*** END ADDITIONAL PHP PROCESSING ***
The text was updated successfully, but these errors were encountered:
gsherwood
changed the title
Tokenizer bug: ternaries in constant scalar expression param default misidentified.
Ternaries used in constant scalar expression for param default misidentified by tokenizer
Apr 12, 2017
Since PHP 5.6 function param defaults (as well as class constants, class properties and static variables) can be initialized with constant scalar expressions, including ternaries.
However, when using such a ternary in a function declaration for the default value:
?
gets misidentified asT_NULLABLE
while I would expect it to beT_INLINE_THEN
:
gets misidentified asT_COLON
while I would expect it to beT_INLINE_ELSE
Test code:
Debug output:
The text was updated successfully, but these errors were encountered: