1.2.714. Mixed Concat And Interpolation¶
Mixed usage of concatenation and string interpolation is error prone. It is harder to read, and leads to overlooking the concatenation or the interpolation.
Fixing this issue has no impact on the output. It makes code less error prone.
There are some situations where using concatenation are compulsory : when using a constant, calling a function, running a complex expression or make use of the escape sequence. You may also consider pushing the storing of such expression in a local variable.
<?php
// Concatenation string
$a = $b . 'c' . $d;
// Interpolation strings
$a = "{$b}c{$d}"; // regular form
$a = "{$b}c$d"; // irregular form
// Mixed Concatenation and Interpolation string
$a = "{$b}c" . $d;
$a = $b . "c$d";
$a = $b . "c{$d}";
// Mixed Concatenation and Interpolation string with constant
$a = "{$b}c" . CONSTANT;
?>
1.2.714.1. Connex PHP features¶
1.2.714.1.1. Suggestions¶
Only use one type of variable usage : either interpolation, or concatenation
1.2.714.1.2. Specs¶
Short name |
Structures/MixedConcatInterpolation |
Rulesets |
|
Exakat since |
0.11.5 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Examples |
|
Available in |