rishal
rishal

Reputation: 3548

Changing PHP 5.4 code to PHP 5.3 to avoid syntax error

How do I change the following two codes so that they can be used in php 5.3

first

return [
    'Authorization: key=' . $this->apiKey,
    'Content-Type: application/json'
];

second

$fields = [
    'registration_ids' => is_string($regIds) ? [$regIds] : $regIds,
    'data' => is_string($data) ?
         [
            'message' => $data,
            'title' => $title,
            'key' => $key
          ] : $data,
    ];

Upvotes: 0

Views: 162

Answers (1)

Jite
Jite

Reputation: 5847

I was not aware that it was legal in 5.5 to initialise arrays with just the [] brackets. Are you sure that your code does not run in 5.3 as it is?

If the issue is the array initialisation (cause the rest of the code seems quite fine), you could try with using ... array ( /**/ ) instead of ... [ /**/ ].
IE:

return array(
  'Authorization: key=' . $this->apiKey,
  'Content-Type: application/json'
);

Upvotes: 1

Related Questions