PHP variables inside echo string are formatted to the new line 😢
@prettier/plugin-php v0.17.2 Playground link
Input:
<?php
function test($var1, $var2) {
echo '<div class="'.$var1.'"></div>
<div class="'.$var2.'"></div>';
}
Output:
<?php
function test($var1, $var2) {
echo '<div class="' .
$var1 .
'"></div>
<div class="' .
$var2 .
'"></div>';
}
Expected Output:
Inline variables should not jump to the new line. Can I control this behavior? Also, valid spacing should be there between quotes and concatenation operators as below.
<?php
function test($var1, $var2) {
echo '<div class="' . $var1 . '"></div>
<div class="' . $var2 . '"></div>';
}
We can’t analyze content inside string
@alexander-akait and what does this exactly mean? 🤔
We don’t know how better keep variables on lines based on html content in string, we don’t know that it is HTML
@alexander-akait okay, is there any workaround for this issue? It makes the code very ugly (rather pretty) and unreadable.
No workarounds, if you concatenate string without html it will be look good, try to split variable on two variables with one var
Workaround is // prettier-ignore above the line you want left alone.
@alexander-akait this is a string concatenation, is it possible to add a flag to not wrap the concat? this consumes a line break that is inside a string, and thinks that it is a "code" line break
echo '<tr>
<td colspan="2"><div class="' . $msg_type . '">' . $message . '</div></td>
</tr>';
Becomes
echo '<tr>
<td colspan="2"><div class="' .
$msg_type .
'">' .
$message .
'</div></td></tr>';
But this doesn't changes
echo '<tr><td colspan="2"><div class="' . $msg_type . '">' . $message . '</div></td></tr>';
which means that the line break (which is inside a string) is considered as "code" line break (which is not).