Preserve Manual Indentation in Concatenated Strings During Code Formatting
Hello, i'm using latest PhpStorm's version. Include PHP auto-formatter does not preserve custom indentation/alignment in multi-line string concatenation expressions, making it difficult to maintain visually structured code (e.g., SQL queries, formatted output).
Do you know a Code Style option to preserve manual indentation within string concatenation expressions, similar to how some formatters handle multi-line arrays or method chains?
Use Cases
- SQL Queries - Aligning SQL keywords for readability
- Formatted Text Output - Building ASCII tables or formatted strings
- Template Strings - Maintaining visual structure in concatenated markup
Steps to reproduce:
Before formatting:
<?php
function buildQuery(){ $query = "SELECT " . "id, name, email " . "FROM " . "users " . "WHERE " . "status = 'active' " . "AND role = 'admin'";
return $query;}
?>
After auto-format (Ctrl+Alt+L):
<?php
function buildQuery() { $query = "SELECT " . "id, name, email " . "FROM " . "users " . "WHERE " . "status = 'active' " . "AND role = 'admin'";
return $query; }
?>
Expected behavior:
<?php function buildQuery() { $query = "SELECT " . "id, name, email " . "FROM " . "users " . "WHERE " . "status = 'active' " . "AND role = 'admin'";
return $query; }
?>
I created support ticket, but i didn't get response since 11/26/2025
Please sign in to leave a comment.
Adammankowski97, this is pure PHP syntax, which is neither attached to a data source nor associated with a particular SQL dialect. This is the reason SQL code style formatting is not applied to this wrapped SQL piece. As a workaround, you can try to create your own customer place template using the User Parameters. Please see here
Thank you for the reply, Aleksandr Molchanov, but unfortunately User Parameters don’t apply to my case.