|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #71927 string interpolation with ${}
Submitted: 2016-03-31 01:27 UTC Modified: 2016-03-31 06:39 UTC
Avg. Score:4.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: 1783946138 at qq dot com Assigned:
Status: Open Package: Scripting Engine problem
PHP Version: 7.0.5 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: 1783946138 at qq dot com
New email:
PHP Version: OS:


 [2016-03-31 01:27 UTC] 1783946138 at qq dot com
The unstable result to use "{}" in string interpolation.It's just because useing space.

Test script:

$my='my value';
echo "This is ${great }<br/>";//output:my value
echo "This is ${ great}<br/>";//output:my value
echo "This is ${ great }<br/>";//output:my value
echo "This is ${great}<br/>";//output:fantastic

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-31 06:39 UTC]
-Summary: string interpolation +Summary: string interpolation with ${} -Package: PHP Language Specification +Package: Scripting Engine problem -Operating System: windows +Operating System: -PHP Version: 5.5.33 +PHP Version: 7.0.5
 [2016-03-31 06:39 UTC]

I think this is intentional. Or at least a side-effect of intentional design.

${expression} basically has two behaviors:
1. If "expression" is a valid variable name then the value of $expression (or empty string if not defined) is interpolated into the string.
2. If "expression" is not a valid variable name then expression is evaluated and the result is expected to be the name of a variable which can be interpolated.

The first three variations are not valid variable names so the expressions "great ", " great", and " great " are evaluated using the constant and the result is effectively ${my} = "my value".
The fourth variation is a valid variable name and so is interpolated as $great = "fantastic".

This is a little different from how the same syntax works outside of strings: the "expression" is *always* treated as an expression.

I feel like that section could go into more detail about how the {$} and ${} syntaxes work and about what all is and is not allowed with each.
 [2023-05-16 10:20 UTC] autoupdatedaily at gmail dot com
Auto Advice Update are sharing latest news about auto, maintaince, car, bus, bilkes, electric bikes and scooters etc. More info to visit: (
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Dec 11 17:01:30 2023 UTC