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
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.
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.
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.
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.
PHP5.3.0+ is required for initializing class-variables using heredoc, your code works fine in PHP 5.3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With