Personally, I don't need the split would work. The main reason for the current approach is that the if/elseif is seen as one logical block. You are saying if this is true, else if this is true.
Splitting would, in my personal opinion, confuse more developers and cause more friction when scanning code. Kind Regards Steve McDougall On Fri, Mar 27, 2026, 16:13 <[email protected]> wrote: > [email protected] > <https://groups.google.com/forum/?utm_source=digest&utm_medium=email#!forum/php-fig/topics> > [image: > Google Groups Logo] > <https://groups.google.com/forum/?utm_source=digest&utm_medium=email/#!overview> > Google > Groups > <https://groups.google.com/forum/?utm_source=digest&utm_medium=email/#!overview> > Topic digest > View all topics > <https://groups.google.com/forum/?utm_source=digest&utm_medium=email#!forum/php-fig/topics> > > - Proposal to allow new line for control structure keywords > (else/elseif) in PER Coding Style > <#m_-4012727915379238210_group_thread_0> - 6 Updates > > Proposal to allow new line for control structure keywords (else/elseif) in > PER Coding Style > <http://groups.google.com/group/php-fig/t/d971d99ab1850f80?utm_source=digest&utm_medium=email> > Amanzhol Zhaparov <[email protected]>: Mar 27 02:49AM -0700 > > 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 <[email protected]>: Mar 27 06:12AM -0500 > > On Fri, Mar 27, 2026 at 6:05 AM Amanzhol Zhaparov < > [email protected]> > wrote: > > > "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 <[email protected]>: Mar 27 12:15PM +0100 > > Hi, > > Il 27/03/2026 12:12, Woody Gilk ha scritto: > >> 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 <[email protected]>: Mar 27 11:19AM > > 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 > > > Matteo Beccati <[email protected]>: Mar 27 12:49PM +0100 > > 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 <[email protected]>: Mar 27 07:41AM -0500 > > > 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. > > Agreed. This should be reported to JetBrains as a bug, as opposed to a > change that affects everyone. > > -- > Woody Gilk (he/him) > https://www.shadowhand.com > Back to top <#m_-4012727915379238210_digest_top> > You received this digest because you're subscribed to updates for this > group. You can change your settings on the group membership page > <https://groups.google.com/forum/?utm_source=digest&utm_medium=email#!forum/php-fig/join> > . > To unsubscribe from this group and stop receiving emails from it send an > email to [email protected]. > -- 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 [email protected]. To view this discussion visit https://groups.google.com/d/msgid/php-fig/CACB5p2v8drrdQzihuFVibpGUKv%2B6RPWGko%2BPP7p58W5WyvxUhw%40mail.gmail.com.
