The PHP community passed a proposal with only one negative vote at the end of April. The content of the proposal is that in the upcoming PHP 8.2, the syntax of using ${} to insert variables in a string will no longer be supported (marked as deprecated) status), and that syntax was removed in PHP 9.
Currently PHP can insert variables into strings with double quotes ("
) and heredoc in the following ways.
Insert the variable directly: “$foo”
Add curly braces outside the variable: “{$foo} ”
$ symbol:
“${foo}”
“${expr}”, equivalent to
(string) ${expr}
var_dump("${foo}"); // Deprecated: Using ${} in strings is deprecated var_dump("${(foo)}"); // Deprecated: Using ${} (variable variables) in strings is deprecated
Analysis Source code: https://gist.github.com/iluuu1994/05427dd74100af8e41ebff3d4201742cIlija Tovilo believes that many other programming languages also use the
${foo} syntax to insert in a string Variables, such as bash and JavaScript (in Template Literals). But their behavior is different from that in PHP. In PHP, this syntax means defining mutable variables. In JavaScript, it supports arbitrary expressions In PHP's current form, options 3 and 4 above are of limited use and can be confusing to developers using other programming languages with similar syntax because they behave completely differently.
var_dump("{$:func()}")
PHP Video Tutorial"
The above is the detailed content of PHP 8.2 no longer supports using ${} to insert variables into strings. For more information, please follow other related articles on the PHP Chinese website!