0

I'd like to interpolate some variables into a HEREDOC string, but it is giving me errors, the code is this:

$htmlViewAppointments .= <<<EOT

        <tr><td>$obj['Year']</td></tr>

EOT;
deceze
  • 510,633
  • 85
  • 743
  • 889
JVE999
  • 3,327
  • 10
  • 54
  • 89
  • 1
    shall we guess the errors or would you like to post them? –  Aug 28 '13 at 19:50
  • I'm going to use that one from now on ---^ – Funk Forty Niner Aug 28 '13 at 19:52
  • The error was, exactly, `Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\Calendar-WithFrames\Utilities\ViewAppointments.php on line 20` – JVE999 Aug 28 '13 at 19:54

1 Answers1

3

Use:

$htmlViewAppointments .= <<<EOT

        <tr><td>{$obj['Year']}</td></tr>

EOT;
  • @deceze: why using constants and later PHP will substitute it with the key! –  Aug 28 '13 at 19:53
  • Except it won't! → http://php.net/manual/en/language.types.string.php#language.types.string.parsing – deceze Aug 28 '13 at 19:54
  • `$obj[Year]` worked fine for me. Also, the answer here works as well, although `$obj[Year]` seems easier to me. – JVE999 Aug 28 '13 at 19:55
  • @Akam: My answer wasn't an exact duplicate, but I deleted it since both of them are similar. No need to be rude :) – Amal Murali Aug 28 '13 at 19:58
  • @AmalMurali: You are welcome to edit mine and add additional info –  Aug 28 '13 at 19:58