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 example of a nowdoc/heredoc as a function parameter #30

Closed
TimWolla opened this issue Jul 18, 2022 · 5 comments · Fixed by #33
Closed

Add example of a nowdoc/heredoc as a function parameter #30

TimWolla opened this issue Jul 18, 2022 · 5 comments · Fixed by #33

Comments

@TimWolla
Copy link
Contributor

TimWolla commented Jul 18, 2022

I believe the indentation requirement of nowdoc/heredoc is not obviously correct within a multi-line function parameter list, as the ending delimiter also needs to be indented compared to e.g. an anonymous function.

<?php

// Right?
var_dump(
    'foo',
    <<<'EOT'
        Line 1
        Line 2
        Line 3
        EOT,
    'bar',
);

// Wrong?
var_dump(
    'foo',
    <<<'EOT'
    Line 1
    Line 2
    Line 3
    EOT,
    'bar',
);

see https://3v4l.org/eGlGY
see #5

@TimWolla
Copy link
Contributor Author

Likewise there is no actual example of the correct format for a multi-line array (or anon function) within a multi-line parameter list. It just says that those do not imply that the parameter list itself is multi-line.

@KorvinSzanto
Copy link
Contributor

I'd argue that:

Instead, the heredoc MUST be indented once past the indentation of the scope it's declared in.

makes it clear that your first example is allowed and your second example is disallowed.

@TimWolla
Copy link
Contributor Author

I don't think it's clear, otherwise I wouldn't have opened this issue. Especially since a function call does not open a new scope if using common terminology (in PHP it's even arguable if if opens a new scope). Also the nowdoc/heredoc section is the only section where the term “scope” appears.

Certainly another explicit example can't hurt?

@TimWolla
Copy link
Contributor Author

Alternatively this could be rephrased entirely:

"The heredoc body and ending delimiter must be indented one additional level compared to the opening delimiter"

@KorvinSzanto
Copy link
Contributor

"Scope" here refers to the indentation scope, not the variable scope. I wouldn't mind adding another example if you want to open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants