Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heredoc syntax error

Tags:

php

mediawiki

For a mediawiki skin, I am getting an error for the following piece of code

    private $_sideboxf = <<<EOD
        <h3>%s</h3>
        <ul class="submenu">
            %s
        </ul>
EOD;

The error is syntax error, unexpected T_START_HEREDOC . I have checked the syntax and I dont know what is wrong. Even the author of the code doesn't understand why I am getting this error when I asked on git.

EDIT: class definition

class SkinTemplate extends QuickTemplate
{
    private $_sideboxf = <<<EOD
    <h3>%s</h3>
    <ul class="submenu">
        %s
    </ul>
EOD;
// Some public function
} // End of Class
like image 829
yayu Avatar asked Jan 04 '12 01:01

yayu


People also ask

What is heredoc syntax?

The heredoc syntax is a way to declare a string variable. The heredoc syntax takes at least three lines of your code and uses the special character <<< at the beginning.

What is a heredoc string?

In computing, a here document (here-document, here-text, heredoc, hereis, here-string or here-script) is a file literal or input stream literal: it is a section of a source code file that is treated as if it were a separate file.

Should I use heredoc?

Heredoc's are a great alternative to quoted strings because of increased readability and maintainability. You don't have to escape quotes and (good) IDEs or text editors will use the proper syntax highlighting.

What is the purpose of using the heredoc and Newdoc in PHP?

Heredoc and nowdoc provide useful alternatives to defining strings in PHP to the more widely used quoted string syntax. They are especially useful when we need to define a string that spans multiple lines (new lines are also interpreted when used in quoted strings) and where use of whitespace is important.


1 Answers

PHP5.3.0+ is required for initializing class-variables using heredoc, your code works fine in PHP 5.3

like image 135
Dr.Molle Avatar answered Sep 24 '22 02:09

Dr.Molle