-
Notifications
You must be signed in to change notification settings - Fork 72
Curlies around variable names in encapsulated strings are mishandled #59
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
Comments
Thanks @jj101k for reporting this issue. You're totally right, I've didn't saw it. The PHP might interpret as this (did not dig enough) :
BUT, this is a special case in PHP, because the real syntax should be :
Because the syntax is I'm saying this because of this behavior :
Here world is not resolved as a constant but as directly the variable name. The tokens from lexer may also differ : ${world} gives : T_DOLLAR_OPEN_CURLY_BRACES"${" T_STRING_VARNAME"world" "}" BUT, as usual in PHP internal, it's not that easy, because the T_STRING_VARNAME is only true with encapsed string. Here the behavior outside an string :
And the result without extra spaces around world :
So, to conclude, you're right I've got multiple bugs on this, but no, "${world}" is not the same as ${world} because it's encapsulated into a string and treated differently, but "${ world }" should be the same as ${world} Expected output : "${world}" is the same as "${\"world\"}"
"${ world }" is the same as ${world}
|
The ouput is now corrected. The first char is no more stripped. The behavior is the same as PHP. PHP Script : <?php
echo "Hello ${world}";
echo "Hello $world";
echo "Hello ${ world }";
echo "Hello " . ${world}; AST Structure : {
"kind": "program",
"children": [
{
"kind": "echo",
"arguments": [
{
"kind": "encapsed",
"value": [
{
"kind": "string",
"value": "Hello ",
"isDoubleQuote": false
},
{
"kind": "variable",
"name": {
"kind": "variable",
"name": "world",
"byref": false
},
"byref": false
}
],
"type": "string"
}
]
},
{
"kind": "echo",
"arguments": [
{
"kind": "encapsed",
"value": [
{
"kind": "string",
"value": "Hello ",
"isDoubleQuote": false
},
{
"kind": "variable",
"name": "world",
"byref": false
}
],
"type": "string"
}
]
},
{
"kind": "echo",
"arguments": [
{
"kind": "encapsed",
"value": [
{
"kind": "string",
"value": "Hello ",
"isDoubleQuote": false
},
{
"kind": "variable",
"name": {
"kind": "constref",
"name": {
"kind": "identifier",
"resolution": "uqn",
"name": "world"
}
},
"byref": false
}
],
"type": "string"
}
]
},
{
"kind": "echo",
"arguments": [
{
"kind": "bin",
"type": ".",
"left": {
"kind": "string",
"value": "Hello ",
"isDoubleQuote": true
},
"right": {
"kind": "variable",
"name": {
"kind": "constref",
"name": {
"kind": "identifier",
"resolution": "uqn",
"name": "world"
}
},
"byref": false
}
}
]
}
],
"errors": []
} |
Output is:
The two items should be the same. Presumably php-parser is treating it like an explicit interpolated expression (eg.
{$world}
) by skipping the first character.The text was updated successfully, but these errors were encountered: