Skip to content

Missing __isset magic method / Compatability Issues with Laravel Collections #171

@Cbrad24

Description

@Cbrad24

The base class for an RR record seems to implement the magic method __get but not __isset as seen here:

netdns2/src/NetDNS2/RR.php

Lines 211 to 219 in df04947

public function __get(string $_name): mixed
{
if (property_exists(get_called_class(), $_name) == false)
{
throw new \NetDNS2\Exception(sprintf('undefined property: %s', $_name), \NetDNS2\ENUM\Error::INT_PARSE_ERROR);
}
return $this->$_name;
}

This caused some compatibility issues with Laravel Collections due to helper methods (used internally in collections) checking if the value was set before retrieveing it as below.
https://github.com/illuminate/collections/blob/e161ebd436f8d1f40c6468f7be2536280044eec5/helpers.php#L88-L89

I have found a workaround by using a callback and invoking the property directly but the following code does not work due to the missing function:

$resolver = new Resolver([
    'nameservers' => [
        '1.1.1.1',
        '8.8.8.8',
    ],
]);

$response = $resolver->query('github.com', 'MX');

// This does not work
return collect($response->answer)
    ->sortBy('preference');

// Using a callback works
return collect($response->answer)
    ->sortBy(fn ($item) => $item->preference)

I know it's not specifically a NetDNS issue however I don't see a reason we couldn't implement the __isset magic method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions