-1

I have two nested statements inside the construction of a string with <<<EOF After the statements I get an error that I don't understand when continuing adding to the string.

The error is unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

function foo_bar() {
    $phrase = "hello world";
    $string = "";

    if (0 == 0) {
        $string .= <<<EOF
        <b>{$phrase}</b>
EOF;
        if (0 == 0) {
            $string .= <<<EOF
            <i> of mine</i>
EOF;
        }
        /* comment out to see the error
        $string .= <<<EOF
        <u> - the END</u>
EOF;
*/
    }

    return $string;
}
add_shortcode('foobar', 'foo_bar');
FFish
  • 10,964
  • 34
  • 95
  • 136
  • 3
    On which line do you get this error? Please mark it with a comment in the code in your question – Rizier123 Jun 08 '15 at 14:41
  • 2
    I get "hello world of mine - the END" when I run this. – cjhill Jun 08 '15 at 14:42
  • 5
    We could discuss whether parse errors are on-topic here but your code [doesn't even trigger one](http://3v4l.org/o24eK). – Álvaro González Jun 08 '15 at 14:42
  • you are never calling you function `function foo_bar() `, at-least i am unable to see that calling code. So please provide full code.because it' s working without error if we write `foo_bar()` instead of `add_shortcode('foobar', 'foo_bar');` – Alive to die - Anant Jun 08 '15 at 14:44
  • 2
    Check if you have a trailing space after `EOF`. – VolenD Jun 08 '15 at 14:46
  • It doesn't work for me either and I can't tell why: http://codepad.org/DIKrVH4Q. – Felix Kling Jun 08 '15 at 14:46
  • Please read my comment carefully. thanks. you are never calling you function function `foo_bar()` , at-least i am unable to see that calling code. So please provide full code.because it' s working without error if we write `foo_bar()` instead of `add_shortcode('foobar', 'foo_bar');` – Alive to die - Anant Jun 08 '15 at 14:49
  • I marked the line where I get the error. – FFish Jun 08 '15 at 14:49
  • 2
    @anantkumarsingh: Since this question is about a *syntax* error, it is irrelevant whether the function is called or not. – Felix Kling Jun 08 '15 at 14:51
  • @FelixKling i found why your code is not working in codepad. You have trailing spaces/tabs in line 19. – Rash Jun 08 '15 at 14:52
  • Actually it's working at my end when i do what i said,if i go with that what he given in code. then blank page is come. that's why i am telling that comment. – Alive to die - Anant Jun 08 '15 at 14:53
  • I have something working now... I replaced the last `EOF` with `UFO` and it works?? I remember you can use whatever. How is this possible? – FFish Jun 08 '15 at 14:53
  • @Rash: Good catch! Then that's likely the issue then, since it would explain the `unexpected T_ENCAPSED_AND_WHITESPACE` part (IMO). This is a verbatim copy of the OP's original code before they added the comment. – Felix Kling Jun 08 '15 at 14:57
  • Geeee, user3584460 was right! is was a trailing space!! Sorry guys, have a nice evening, cheers. – FFish Jun 08 '15 at 14:58
  • @FFish: You seem to have fixed the issue inadvertently when you added the comment around the code block. – Felix Kling Jun 08 '15 at 15:00

1 Answers1

0

So the gist of the discussion in the comments above.

Check for trailing spaces after EOF;

Rash
  • 7,677
  • 1
  • 53
  • 74