0

I get a syntax error when I use heredoc syntax to push values into array

$theArray = array();

$theArray[] = <<<EOT
some values here
EOT;

$theArray[] = <<<EOT
some values here
EOT;

I can't figure out what's wrong with this code.

gabric
  • 1,865
  • 2
  • 21
  • 32
  • be sure that there isn't any space before `EOT;` – Luca Rainone Nov 19 '13 at 13:38
  • Your code is working fine, May be you have an error in some where else? can you post your error_log here ? – Krish R Nov 19 '13 at 13:41
  • And make sure there isn't anything after `<< – Funk Forty Niner Nov 19 '13 at 13:41
  • I have no access to error log, anyway even my editor seems not to be happy with that syntax http://i42.tinypic.com/2s8snz8.gif – gabric Nov 19 '13 at 13:42
  • @gabric: That's not a PHP error. It's specific to your IDE. I suggest you edit the question and add this detail. – Amal Murali Nov 19 '13 at 13:44
  • @AmalMurali: actually I'm getting a blank page when I try to run this code into the webserver. If I just remove one of the array assignments it works fine. – gabric Nov 19 '13 at 13:45
  • @gabric: Add the following to the very top of your script (to enable error reporting) and refresh the page: `ini_set('display_errors',1); error_reporting(E_ALL);`. – Amal Murali Nov 19 '13 at 13:46

1 Answers1

0

It should work just fine. Doing a print_r($theArray); would output:

Array
(
    [0] => some values here
    [1] => some values here
)

Demo.

If you're getting parse errors, double-check and make sure there is no whitespace after the three angled brackets in the beginning and/or end.

Amal Murali
  • 75,622
  • 18
  • 128
  • 150
  • I just noticed that there was a white space after the three brackets... thanks for the support – gabric Nov 19 '13 at 13:49