php-fig / per-coding-style

PER coding style
262 stars 26 forks source link

Consistently use php opening tag #74

Closed ravage84 closed 1 year ago

ravage84 commented 1 year ago

Which is mandated by 3. Declare Statements, Namespace, and Import Statements, anyway.

Kinda "eat your own dog food".

Plus, it makes it even more clear in what file type context the code examples are.

Lastly, this also fixes thie following oddly looking (and unnecessary) whitespace in 7.1 Short Closures:

grafik

Crell commented 1 year ago

I don't think this really applies here. I almost never see the PHP opening tags in markdown code blocks. The intent of the referenced section is that in a file you must start with the open tag, and use the long-tag version. That doesn't really apply to code snippets.

Leaving this open to see if anyone else on the team disagrees, but I'm voting won't-fix here.

Crell commented 1 year ago

(The unnecessary extra line in that one code block can be fixed in a separate PR.)

mbniebergall commented 1 year ago

Including the opening PHP tag <?php is not standard for code snippets. See examples of no opening PHP tags at:

Some PSrs do include the opening tag, when conveying the context of the file, as seen in:

alekitto commented 1 year ago

I agree that the opening tag should not be mandatory for code snippets.
At the same time, I can see the inconsistency between the various PSRs: for example in PSR-3, the code block containing the interpolate function has an unnecessary opening tag, while the interface declarations (which are entire files) correctly have it.

I’m voting for wont-fix here, but probably we should define a general rule for code blocks/snippets

KorvinSzanto commented 1 year ago

I don't see value in including the PHP tag in code snippets unless the snippet encompasses the entire file so I agree this isn't something we should do.

samdark commented 1 year ago

I agree that there's no sense in adding it in these cases.

ravage84 commented 1 year ago

(The unnecessary extra line in that one code block can be fixed in a separate PR.)

Separate PR: #80

ravage84 commented 1 year ago

[...] At the same time, I can see the inconsistency between the various PSRs: for example in PSR-3, the code block containing the interpolate function has an unnecessary opening tag, while the interface declarations (which are entire files) correctly have it.

Actually, I disagree on that specific one because it could be the full code of this file., as well. Adding a php opening tag implicitly hints at that & frames the whole code.

grafik

https://www.php-fig.org/psr/psr-3/#12-message

This would be a prime example where I would expect the php opening tag

ravage84 commented 1 year ago

While I like the consistency of having opening tags everywhere, I can see it being "too much", especially for one liners.

What do you think of the alternative in #81?