I have a class like this:
class main {
private static $content;
public function ini() {
include 'content_a.php';
self::$content = new $content;
}
public function content($snippet, $addclass=false) {
return self::$content->snippet;
}
}
It parses some input and determines which file to include in ini(), which runs once at the top of each pageload. In this example, it includes content_a.php
, but there are more (content_b.php
, content_c.php
, ...). The method saves the content of the file to the $content property for use by content(), which is called numerous times throughout the rest of the script.
The file content_a.php looks like this:
class content {
public $text = <<<FOO
<div class="default $addclass">Hello World</div>
FOO;
}
No matter whether it's a, b, or c, it always looks the same - only the actual content within the heredoc differs. Each file contains of number of snippets; in this example, there's only one ($text
).
I'm rendering a snippet like this:
echo $main->content('text');
...which works perfectly. However, when I try to pass through a parameter $addclass
like this...
echo $main->content('text', 'bar');
...I'm getting the error unexpected T_VARIABLE, expecting T_END_HEREDOC
. If I wrap the variable in curly brackets, I get unexpected T_CURLY_OPEN, expecting T_END_HEREDOC
.
Any ideas what I'm doing wrong - or is there a better way to do this?