This question has aged a bit but to provide a more complete answer with a few possible solutions. Conditionals are not allowed "inside" a heredoc but you can use conditionals with heredocs.
These examples should give you an idea of heredoc usage. Take note that the first line of a heredoc starts with 3 less than symbols and some arbitrary text with no space at the end of the first line. Press enter. The heredoc must be closed similarly. As you probably know, the text used to open the heredoc must be used to close it which is typically but not required to be followed by a semicolon. Be sure no trailing whitespace or characters follow the semicolon or last text character and then press enter.
function doSomething($username = '', $status_id = '') {
if ('' != $username && '' != $status_id) {
$reply = <<<EOT
<a class ="reply" href="viewtopic.php?replyto=@{$username}&status_id={$status_id}&reply_name={$username}"> reply </a>
EOT;
} else {
$reply = <<<EOT
<h2>The username was not set!</h2>
EOT;
}
return $reply;
}
echo doSomething('Bob Tester', 12);
echo doSomething('Bob Tester');
echo doSomething('', 12);
Depending on your specific situation you may find it helpful to use a class to do your comparisons that you wanted to use in your heredoc. Here is an example of how you may do that.
class Test {
function Compare($a = '', $b = '') {
if ($a == $b)
return $a;
else
return 'Guest';
}
};
function doSomething($username = '') {
$Test = new Test;
$unme = 'Bob Tester';
$reply = <<<EOT
<h2>Example usage:</h2>
Welcome {$Test->Compare($username, '')}<br />
<br />
Or<br />
<br />
Welcome {$Test->Compare($username, $unme)}
EOT;
return $reply;
}
echo doSomething('Bob Tester');