-2

I'm getting a parse error:
Parse error: syntax error, unexpected '[', expecting ',' or ';' in index.php on line 23

Line 23 is this:

echo "<h3>Message received from: </h3>" . $er->GetMessage($i)["header"]->fromaddress;

I changed the syntax in all similar lines to

echo "<h3>Message received from: </h3>" . $er->GetMessage($i)["header"]['fromaddress'];

but I get the identical error message.

$er is an array of email messages. Each array element is an array of key-value pairs, and the value for the key 'header' is a long array of key-value pairs.

The function $er->GetMessage($i) returns an array, so this sytax
$er->GetMessage($i)["header"]['fromaddress']

seems like it would work. So, I'm at a loss. The arrow syntax doesn't make sense to me at all, because 'fromaddress' is not a member of 'header''header' is not an object.

What am I missing? I did a search on "Parse error: syntax error, unexpected '[', expecting ',' or ';'" and I found one match. The solution was "- the php wasn't on automatic update so now it is the site is working fine." I don't think this applies to my issue.

The code is below.
Line 23, the line that triggered the error message, is in the for loop.
echo "<h3>Message received from: </h3>" . $er->GetMessage($i)["header"]->fromaddress;

This is php between body tags:

    for ($i=0;$i<$er->GetInboxCount();$i++)
    { // fromaddress, date, subject are from imap_headerinfo
        echo br.br;
        echo "<h3>Message received from: </h3>" . $er->GetMessage($i)["header"]['fromaddress'];  
        echo br.br;
        echo "<h3>Message received on: </h3>" . $er->GetMessage($i)["header"]['date'];
        echo br.br;
        echo "<h3>Subject: </h3>" . $er->GetMessage($i)["header"]['subject'];
        echo br.br;
        echo "<h3>Message in text format:</h3>" . $er->GetMessage($i)['body_text'];
        echo br.br;
        echo "<h3>Message in html format: </h3>" . $er->GetMessage($i)['body_html'];
jana
  • 81
  • 3
  • 10
  • I tried at least 10 times to include that stray bracket at the end. I was using ctrl-K but it wouldn't work not matter what. – jana Aug 31 '16 at 08:49
  • 1
    Try: $message = $er->GetMessage($i); $message["header"]->fromaddress; – rad11 Aug 31 '16 at 08:51
  • 1
    What version of PHP are You running? The `func()[...]` syntax is suuported on 5.4+ (see http://php.net/manual/en/language.types.array.php#example-105). – Roman Hocke Aug 31 '16 at 08:52
  • Tip: For a *syntax error* you only need to include the relevant lines immediately surrounding the line that the error tells you. No need to post your entire application… – deceze Aug 31 '16 at 08:55
  • After running phpversion(), I seem to be running 5.2.17. So, what syntax can I use? – jana Aug 31 '16 at 09:07
  • Ok, I won't post so much last time. I remember reading that you're supposed to post the code that would allow someone else to reproduce the error. – jana Aug 31 '16 at 09:08
  • rad11, that worked. Error gone. Thank you! – jana Aug 31 '16 at 09:15

1 Answers1

0

Try to use this:

$foo = $er->GetMessage($i);
echo "<h3>Message received from: </h3>" . $foo["header"]->formadresss;
Patrick Mlr
  • 2,955
  • 2
  • 16
  • 25