Fork me on GitHub
a Sensio Labs Product

Remote Void (v2.18.1) edition

Rule explicit_string_variable

Converts implicit variables into explicit ones in double-quoted strings or heredoc syntax.


The reasoning behind this rule is the following: - When there are two valid ways of doing the same thing, using both is confusing, there should be a coding standard to follow - PHP manual marks "$var" syntax as implicit and "${var}" syntax as explicit: explicit code should always be preferred - Explicit syntax allows word concatenation inside strings, e.g. "${var}IsAVar", implicit doesn’t - Explicit syntax is easier to detect for IDE/editors and therefore has colors/highlight with higher contrast, which is easier to read Backtick operator is skipped because it is harder to handle; you can use backtick_to_shell_exec fixer to normalize backticks to strings


Example #1

--- Original
+++ New
@@ -1,4 +1,4 @@
-$a = "My name is $name !";
-$b = "I live in $state->country !";
-$c = "I have $farm[0] chickens !";
+$a = "My name is ${name} !";
+$b = "I live in {$state->country} !";
+$c = "I have {$farm[0]} chickens !";

Rule sets

The rule is part of the following rule set:


Using the @PhpCsFixer rule set will enable the explicit_string_variable rule.

The logo is © 2010-2014 Sensio Labs