Skip to content

Wrong error message regarding HEREDOC indentation level limits #5501

Open

Description

@dan-software-engineer

the error message regarding HEREDOC indentation limit has logically incorrect text.

steps to reproduce:

  1. navigate to https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
  2. find the sub-section titled "Closing identifier must not be indented further than any lines of the body"
  3. find the output of the code from that example - "Parse error: Invalid body indentation level (expecting an indentation level of at least 3) in example.php on line 4"

issue: the error message says that the indentation level must be AT LEAST 3, i.e. "indentation level >= 3".
this contradicts and is completely opposite to the PHP rule (mentioned in the code example title) "Closing identifier must NOT be indented further than any lines of the body"; in this example - "indentation level <= 3".
the code example title contains the correct PHP rule - that the indentation of the closing identifier must NOT be greater than the maximum indentation of the string body.
the error messages from the exception contains wrong and opposite wording.
this error message needs to be fixed both in PHP source-code and in the documentation on that page.

thank you.

Activity

  1. MaximePinot commented on Apr 20, 2026

    @MaximePinot

    To me, both the example's title and the PHP error are correct here.

    Example 3 Closing identifier must not be indented further than any lines of the body

    This is correct. If the closing identifier is not "indented further than any lines of the body", than means that the indentation level of one or more lines is lower than the indentation level of the closing identifier.

    OK ✅ KO ❌
    <?php
    echo <<<END
     a // at column 2
      b // at column 3
       c // at column 4
    END; // at column 1, *not* indented further than any lines of the body
    <?php
    echo <<<END
     a // at column 2
          b // at column 7
        c // at column 4
        END; // at column 4,  *is* indented further than the first line

    Parse error: Invalid body indentation level (expecting an indentation level of at least x)

    This is correct. x is the column where the closing identifier starts.

    Closing identifier starts at column 2 Closing identifier starts at column 3 Closing identifier starts at column 3
    <?php
    echo <<<END
    test
     END; // column 2 = one indentation level
    <?php
    echo <<<END
    test
      END; // column 3 = two indentation level
    <?php
    echo <<<END
    test
       END; // column 4 = three indentation level
    Parse error: Invalid body indentation level
    (expecting an indentation level of at least 1)
    Parse error: Invalid body indentation level
    (expecting an indentation level of at least 2)
    Parse error: Invalid body indentation level
    (expecting an indentation level of at least 3)

    I agree that the example's title could be improved, though. As a non-native English speaker, it was not very clear to me either when I first read it.

    Perhaps, we could replace it with one of the followings?

    • The closing identifier must not be indented more than any lines of the body
    • The closing identifier must be at the same or lower indentation level as any lines of the body

    WDYT?

  2. dan-software-engineer commented on Apr 22, 2026

    @dan-software-engineer
    Author

    @MaximePinot thank you for the detailed commend and suggestions.

    I agree with you that an example title like the one you have suggested "The closing identifier must not be indented more than any lines of the body" is very clear and simple to understand for any non native-english speakers. That would be a nice improvement!

    however my main concern with this bug report was the php error message "Parse error: Invalid body indentation level (expecting an indentation level of at least 3)".

    the issue is that the expression "at least 3" means "minimum 3", which implies that any indentation level higher or equal to 3 is acceptable, for example an indentation level of 100 or 1000 would be acceptable according to this formulation, but that would be wrong in practice.

    so the correct wording needs to be the opposite - "at most 3" - not "at least 3", because "at most" means "maximum" (i.e. equal or lower), which in that error message would mean "expecting indentation level 0 or 1 or 2 or 3", all of which would be valid for that documentation example.

    to put it in mathematical terms, the error message says "expecting >=", but it should be the opposite "expecting <=".

    let me know if that makes sense, and let's see who can fix this the error message in the php source-code, not just in the documentation.

    thank you.

  3. MaximePinot commented on Apr 22, 2026

    @MaximePinot

    I still think that the PHP error message is correct. 😇

    The PHP error message is about the “body” ("Invalid body indentation level" -- therefore the lines between the delimiters). It is correct to say that all lines of the body must have an "indentation level of at least 3" (>=) if the closing identifier starts at column 3.

    In other words: all lines of the body must have a higher or equal indentation level than the closing identifier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions