0

I have the following PHP method in a class:

function pullMsg() {
    $msgOut = [];
    if (count($this->msgQin) > 0) {
        $msg = array_pop($this->msgQin);
        $msgArr = explode('::', msg);
        $msgOut['sender'] = msgArr[0];
        $msgOut['timestamp'] = msgArr[1];
        $msgOut['message'] = msgArr[2];
    }
    return $msgOut;
}

I have one machine, running PHP 5.6 that is using this class and has no problem with it. But on a machine running PHP 5.4, including this file throws up the error:

Parse error: syntax error, unexpected '[' in /home/intranet/lib/libIpcMessaging.php on line 77

Line 77 in this case is: $msgOut['sender'] = msgArr[0]; – ie, the first time I try to assign a value to a member of the array. Bear in mind this error doesn't occur when the method is called - it happens immediately the file is included. Any ideas?

Dick Kennedy
  • 153
  • 2
  • 13

0 Answers0