Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php8 support #42

Open
azpanel opened this issue Oct 8, 2023 · 2 comments
Open

php8 support #42

azpanel opened this issue Oct 8, 2023 · 2 comments

Comments

@azpanel
Copy link

azpanel commented Oct 8, 2023

During inheritance of Iterator: Uncaught think\exception\ErrorException: Return type of IPTools\Network::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/wwwroot/project/vendor/s1lentium/iptools/src/Network.php:326

@azpanel
Copy link
Author

azpanel commented Oct 8, 2023

This error is due to the fact that in PHP 8.1, return types have been added to the methods of built-in interfaces and classes, a change that may cause some compatibility issues. In your code, the return type of IPTools\Network::current() method is not compatible with the built-in Iterator::current(): mixed, hence the error.

There are two ways to solve this problem:

  1. You can add the #[\ReturnTypeWillChange] attribute to the IPTools\Network::current() method to temporarily suppress this notice. This is a temporary solution and not a long-term one. This attribute might be removed in future versions of PHP. The code for this solution is as follows:
#[\ReturnTypeWillChange]
public function current()
{
    // ... your code here ...
}
  1. A better solution is to modify the return type of the IPTools\Network::current() method to be compatible with Iterator::current(): mixed. You need to check the implementation of this method and ensure it can return a value of any type (mixed type). If it cannot, you may need to modify the implementation of this method or the design of the entire class. The code for this solution might be as follows:
public function current(): mixed
{
    // ... your code here ...
}

Please note that both solutions require you to have the permission to modify the source code. If you cannot modify the source code, you may need to contact the maintainers of this library and ask them to fix the issue.

@azpanel
Copy link
Author

azpanel commented Oct 8, 2023

Call code

public static function calculatingIpv6Subnets(string $ipv6_cidr): array
    {
        $subnets_64 = [];
        $networks = \IPTools\Network::parse($ipv6_cidr)->moveTo('64');
        foreach ($networks as $network) {
            $subnets_64[] = (string) $network;
        }
        return $subnets_64;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant