lundi 8 juin 2015

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');

Aucun commentaire:

Enregistrer un commentaire