Reputation: 31
I have an issue that is quite puzzling me.
I have a php script running on 2 different shared hostings.
On the first one everything runs flawlessly. On the second one it outputs me a syntax error and doesn't work.
Here is the syntax error and the code that is giving issues:
Parse error: syntax error, unexpected '[' in /home/click/public_html/extension/include/config.php on line 13
Code:
function pem2der($pem_data) {
return base64_decode(trim(explode('-----', $pem_data)[2]));
}
I can't seem to find the issue. Anyone could give me some help? Thanks in advance
Upvotes: 2
Views: 39
Reputation: 5520
It because you're using something called array dereferencing which basically means that you can access a value from an array returned by a function direct. this is only supported in php>=5.4
To solve your issue, do something like this:
function pem2der($pem_data) {
$exploded = explode('-----', $pem_data);
$retStr = base64_decode(trim($exploded[2]));
return $retStr;
}
Upvotes: 0
Reputation: 219924
It's because you're doing array dereferencing which is only available in PHP as of version 5.4. You have it locally but your webhost does not. That's why you should always make sure your development environment matches your production environment.
Upvotes: 3