PSR-12 question about "endif" "endwhile" etc

262 views
Skip to first unread message

Liam Hennessy

unread,
Jul 15, 2021, 5:20:46 PM7/15/21
to PHP Framework Interoperability Group

Greetings!

According to Section 5 of PSR-12 (Control Structures):

The body of each structure MUST be enclosed by braces. This standardizes how the structures look and reduces the likelihood of introducing errors as new lines get added to the body.

Does this mean that endif, endwhile, endfor, endforeach, and endswitch are not permitted by PSR-12?

It would be helpful if PSR-12 was more explicit about this, even if the consensus is that you MAY use them, as it is easy to overlook this point completely or misinterpret this point as a strict exclusion.

As a new member, please accept my thanks for your time and effort.

Regards,

Liam

Woody Gilk

unread,
Jul 15, 2021, 8:13:54 PM7/15/21
to php...@googlegroups.com
I think your interpretation is correct:

endif and similar control structures are not allowed. 

Sent from my iPhone

On Jul 15, 2021, at 5:20 PM, Liam Hennessy <li...@boxclever.ca> wrote:


--
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 on the web visit https://groups.google.com/d/msgid/php-fig/f0d9e0c7-9957-45fe-9721-5d3e2f71b613n%40googlegroups.com.

Korvin Szanto

unread,
Jul 17, 2021, 6:06:07 PM7/17/21
to php...@googlegroups.com
Hi Liam,
We discussed alternative control syntax at least once[0] (I recall a few times) and decided that we wanted to leave them unspecified for fear of needing to codify mixed PHP and HTML where they are primarily used. That says PSR-12 specifically requires control structures use brackets in the section you quoted but there's nothing stopping you from using PSR-12 and allowing them in your own projects.


Best wishes,
Korvin

--
Reply all
Reply to author
Forward
0 new messages