Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add section describing nowdoc and heredoc #5

Merged
merged 1 commit into from
Jul 17, 2022

Conversation

KorvinSzanto
Copy link
Contributor

This PR adds the beginnings of a section that describes the usage of heredoc / nowdoc statements. I don't necessarily expect the rules contained in this PR to be accepted without discussion but I wanted to get something down to kick-start discussion.

Potentially contentious points:

  1. Nowdoc recommended over heredoc. We intentionally tried to avoid SHOULD in PSR-12 since SHOULD isn't a very good basis for a code style guide. However I think this is a place where it makes sense for us to recommend folks don't use heredocs where nowdocs are more appropriate since it's not a matter of codestyle, more a matter of best practices. That said, maybe this should be left out and we should instead focus on things that are strictly codestyle and not related to potential misuse.
  2. Heredoc / nowdoc declared on the same line as the context it's being declared into. This idea is really hard to put into words but basically the thinking is we don't want folks to add a newline between the = and the nowdoc / heredoc declaration when assigning a heredoc to a variable, and we don't want heredoc to modify how function arguments are provided and so this rule attempts to require the implementor to put the heredoc opening on the same line as the context using it always. To be clear it's totally fine to use a heredoc / nowdoc in a multiline function / method call, it's just that the heredoc opening itself should not command it's own line if not otherwise required.
  3. Indent heredocs once time past the current scope. I'd wager most heredocs today are not indented at all and so this is probably a big departure from what most people are used to. I think it's definitely better to have the heredoc / nowdoc indented to at least match the current scope rather than have it lack any indention at all.

@KorvinSzanto KorvinSzanto mentioned this pull request Feb 4, 2022
25 tasks
spec.md Show resolved Hide resolved
spec.md Show resolved Hide resolved
@samdark samdark added enhancement New feature or request core labels May 24, 2022
@KorvinSzanto KorvinSzanto merged commit 0e8f81a into php-fig:master Jul 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants