Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2012
    Posts
    85
    Thanks
    53
    Thanked 0 Times in 0 Posts

    EOT Heredoc Parse Error

    I get a funny error when the "EOT" or the "$end" is indented.

    PHP Code:
    <?php
    echo <<< EOT
        HELLO!
    EOT;
    ?>
    which I researched to be exactly the same as:

    PHP Code:
    <?php
    echo <<< PINEAPPLES
        HELLO!
    PINEAPPLES;
    ?>
    ^ works. But if I indent the $end
    PHP Code:
    <?php
    echo <<< PINEAPPLES
        HELLO!
        PINEAPPLES;
    ?>
    it produces an error?:

    Parse error: syntax error, unexpected $end, expecting T_VARIABLE or T_END_HEREDOC or T_DOLLAR_OPEN_CURLY_BRACES or T_CURLY_OPEN

    This seems really funny to me, does anyone know why it does this? I'm more curious as to learn why it gives me an error than "You just can't."
    I indent all my code, so if I was territory that is indented 20 times, that would mean I would have to put the $end on the very first indent?
    Last edited by RonnyNishimoto; 07-20-2012 at 05:17 AM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You cannot indent the ending delimiter (this is documented as such as well). You must put it on a line of its own, and it must not have any preceding whitespace.

    So I'm afraid the answer is "You just can't". Its the way the parsing engine works on the heredoc and nowdoc syntax.

  • Users who have thanked Fou-Lu for this post:

    RonnyNishimoto (07-20-2012)

  • #3
    New Coder
    Join Date
    Jul 2012
    Posts
    85
    Thanks
    53
    Thanked 0 Times in 0 Posts
    :O That really, really sucks. If that's the case, it's pretty much worthless. Thanks again Fou!
    Last edited by RonnyNishimoto; 07-20-2012 at 02:58 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •