I am working on a AST builder for PHP and looking at a few grammar files for PHP I am noticing the
T_ENCAPSED_AND_WHITESPACE
and my AST builder fails for HEREDOCS/NOWDOCS where the token is used. I can't seem to find a representation of that token and what kind of regex matches
It's caused by using quoted array keys in a double-quoted string, among other things. e.g.
$foo['bar'] = 'baz';
echo "$foo['bar']";
PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
The proper syntaxes are:
echo "$foo[bar]"; // no quotes on the array key
echo "{$foo['bar']}"; // extended {} notation