Proposal to allow new line for control structure keywords (else/elseif) in PER Coding Style

38 views
Skip to first unread message

Amanzhol Zhaparov

unread,
Mar 27, 2026, 7:05:41 AM (3 days ago) Mar 27
to PHP Framework Interoperability Group

Hello PHP-FIG members,

I would like to start a discussion regarding a potential refinement or an allowed alternative in the PER Coding Style (successor to PSR-12), specifically concerning section 5.1 (if, elseif, else).

Currently, the standard strictly requires else and elseif to be on the same line as the closing brace of the previous block:

PHP
if ($expr1) {
  // body
} else {
  // body
}

The Problem: Code Folding & Scannability In modern development environments (JetBrains PhpStorm, VS Code, Sublime Text), the "Code Folding" feature is essential for navigating large files. When a developer collapses an if block following the PSR-12 standard, the else keyword often gets hidden or visually merged into a single line like: if ($expr1) { ... } else {

This makes it difficult to quickly scan the code to see if an alternative logic branch exists without unfolding every block.

The Proposal: I propose to allow (or recommend as an alternative) placing else and elseif on a new line, similar to the Allman style but keeping the opening brace on the same line as the keyword:

PHP
if ($expr1) {
  // if body
}
elseif ($expr2) {
  // elseif body
}
else {
  // else body
}

Benefits:

  1. Improved Visual Hierarchy: Each logical branch starts on its own line, making the structure clear at a glance.

  2. Better IDE Integration: When the if block is folded, the else or elseif remains clearly visible on the next line, preserving the "map" of the logic.

  3. Consistency: It aligns with how many developers naturally separate distinct logical steps.

I understand that PSR-12 aimed for vertical compactness, but with high-resolution monitors and the heavy use of IDE folding features, the "saved line" often comes at the cost of readability.

I would love to hear the community's thoughts on whether the PER Coding Style could be updated to allow this formatting as a valid alternative.

Best regards, Amanzhol Zhaparov

Woody Gilk

unread,
Mar 27, 2026, 7:13:13 AM (3 days ago) Mar 27
to php...@googlegroups.com
On Fri, Mar 27, 2026 at 6:05 AM Amanzhol Zhaparov <balloon...@gmail.com> wrote:

Benefits:

  1. Improved Visual Hierarchy: Each logical branch starts on its own line, making the structure clear at a glance.

  2. Better IDE Integration: When the if block is folded, the else or elseif remains clearly visible on the next line, preserving the "map" of the logic.

  3. Consistency: It aligns with how many developers naturally separate distinct logical steps.

I understand that PSR-12 aimed for vertical compactness, but with high-resolution monitors and the heavy use of IDE folding features, the "saved line" often comes at the cost of readability.

I would love to hear the community's thoughts on whether the PER Coding Style could be updated to allow this formatting as a valid alternative.


I disagree and prefer the current style.

--
Woody Gilk (he/him)
https://www.shadowhand.com

Matteo Beccati

unread,
Mar 27, 2026, 7:15:20 AM (3 days ago) Mar 27
to php...@googlegroups.com
Hi,

Il 27/03/2026 12:12, Woody Gilk ha scritto:
>> I would love to hear the community's thoughts on whether the PER
>> Coding Style could be updated to allow this formatting as a valid
>> alternative.
>
> I disagree and prefer the current style.

100% with Woody here.


Cheers
--
Matteo

Mathieu Rochette

unread,
Mar 27, 2026, 7:19:31 AM (3 days ago) Mar 27
to php...@googlegroups.com
Hi!

it's not obvious what is the issue and how much better it would be if this was accepted, probably worth sharing before/after screenshots of the diff it makes in the different IDEs

regards,

Mathieu Rochette

--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/php-fig/cb762a86-90a3-4192-b80c-c1627be4255bn%40googlegroups.com.

publickey - mathieu@rochette.cc - 0x8D30BA0E.asc
signature.asc

Matteo Beccati

unread,
Mar 27, 2026, 7:49:45 AM (2 days ago) Mar 27
to php...@googlegroups.com
Hi,

Il 27/03/2026 12:19, Mathieu Rochette ha scritto:
> it's not obvious what is the issue and how much better it would be if
> this was accepted, probably worth sharing before/after screenshots of
> the diff it makes in the different IDEs

TBH I rarely use the feature and I hadn't noticed PhpStorm folds the
code in a weird way with if/elseif/else.

I do now, and I think it's JetBrains that should fix code folding,
especially given they otherwise seem to suppor PER Coding Style.


Cheers
--
Matteo

Woody Gilk

unread,
Mar 27, 2026, 8:42:28 AM (2 days ago) Mar 27
to php...@googlegroups.com
Agreed. This should be reported to JetBrains as a bug, as opposed to a change that affects everyone.
Reply all
Reply to author
Forward
0 new messages