PHP code breaks updating from PHP 5.4 to PHP 5.6

Hello,

I have the following code below that has been working fine on PHP 5.4, but when ran on PHP 5.6 if just breaks and prints out the code to the page instead of running it. I’ve been looking around online but can’t find anything to suggest why it has been happening.

It seems to break at every => or -> in this single file. In every other file where there’s a -> or => it works totally fine.

[php]
function countryCityFromIP($ipAddr)
{
if ($ipAddr == “0.0.0.0”) {
return null;
}
$country = ip_details($ipAddr);
$country = strtolower($country);
$image = “…/images/icons/{$country}.png”;

return $image;

}

function ip_details($ip) {
$newIp = explode(":", $ip);
$ip = $newIp[0];
$json = file_get_contents(“http://ipinfo.io/{$ip}/json”);
$details = json_decode($json);
return $details->country;
}

function getSteamDetails($steamid) {
$_STEAMAPI = $_SESSION[“apikey”];

$url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$_STEAMAPI&steamids=" . toCommunityID($steamid);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$json_decoded = json_decode(curl_exec($ch));
return $json_decoded->response->players[0];

}

function getVacBans($steamid) {
$_STEAMAPI = $_SESSION[“apikey”];

$url = "http://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key=$_STEAMAPI&steamids=" . toCommunityID($steamid);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$json_decoded = json_decode(curl_exec($ch));
return $json_decoded->players[0];

}
[/php]

When every the code runs a -> it just prints out all the code after the -> as shown in the code below (Can’t add picture in to show it). It prints out all the code from line 20 and below.

Output:

country; } function getSteamDetails($steamid) { $_STEAMAPI = $_SESSION[“apikey”]; $url = “http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$_STEAMAPI&steamids=” . toCommunityID($steamid); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $json_decoded = json_decode(curl_exec($ch)); return $json_decoded->response->players[0]; } function getVacBans($steamid) { $_STEAMAPI = $_SESSION[“apikey”]; $url = “http://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key=$_STEAMAPI&steamids=” . toCommunityID($steamid); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $json_decoded = json_decode(curl_exec($ch)); return $json_decoded->players[0]; } ?>

Any help would be greatly appreciated on understanding on why this works in PHP 5.4 and not PHP 5.6.

I am presently running 5.6.1 and ran a snippet of code without issue:
[php]
function ip_details($ip) {
$newIp = explode(":", $ip);
$ip = $newIp[0];
$json = file_get_contents(“http://ipinfo.io/{$ip}/json”);
$details = json_decode($json);
return $details->country;
}

echo ip_details( ‘ip’ );
[/php]

And it returned GB.

After checking the change log, the only thing that changed was this:

5.6.0 Invalid non-lowercased variants of the true, false and null literals are no longer accepted as valid input, and will generate warnings.

Strange how that works for you. I’ve had many people running the code and all having the same issue with it just printing the code out. I have also been told that the problem happens on PHP 5.5 as well.

I just tried playing around with the code, but have come across something even more weird now.

I created a test file called test.php and then included the file which was having the issue called util.php.

In the test.php file I put:

[php]<?php

ini_set(‘display_errors’,1);
ini_set(‘display_startup_errors’,1);
error_reporting(-1);

include(‘includes/util.php’);

echo ip_details();

?>[/php]

Then all I had in util.php was:

[php]<?

function ip_details() {
return “test”;
}

?>[/php]

Yet I’m now getting the following error: Fatal error: Call to undefined function ip_details() in /var/www/test.php on line 9

I am limited in what I can do without more valid data to test. But this is what I have.



Well, are you 100% sure that your util file is being included? It is saying that it is not there.
It is not seeing the function name and therefore must not being included correctly.

Sponsor our Newsletter | Privacy Policy | Terms of Service