Skip to content

Unexpected behaviour with Isset() and empty() #79

@juangiordana

Description

@juangiordana

Hello,

I'm seeing a strange behaviour with isset() and empty(), both returning invalid results for valid data.

$ipAddress = '128.101.101.200';

$reader = new \GeoIp2\Database\Reader('/usr/share/GeoIP/GeoLite2-Country.mmdb');
$countryRecord = $reader->country($ipAddress);

echo $countryRecord->country->name , "\n"; // United States
$isset = isset($countryRecord->country->name);
var_dump($isset); // bool(false) ?
$empty = empty($countryRecord->country->name);
var_dump($empty); // bool(true) ?
$empty = ($countryRecord->country->name == '');
var_dump($empty); // bool(false)
echo "\n";

$reader = new \GeoIp2\Database\Reader('/usr/share/GeoIP/GeoLite2-City.mmdb');
$cityRecord = $reader->city($ipAddress);

echo $cityRecord->country->name , "\n"; // United States
$isset = isset($cityRecord->country->name);
var_dump($isset); // bool(false) ?
$empty = empty($cityRecord->country->name);
var_dump($empty); // bool(true) ?
$empty = ($cityRecord->country->name == '');
var_dump($empty); // bool(false)
echo "\n";

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions