Reputation: 5107
In php the function
openssl_free_key
is deprecated and not includde in php 8. Can somebody give an alternative for it?
Upvotes: 3
Views: 5887
Reputation: 91
In case you need to maintain compatibility with older php version, you can do something like this:
// $privateKey = openssl_pkey_new([ ... ]);
if (PHP_VERSION_ID < 80000) {
openssl_free_key($privateKey);
}
Upvotes: 4
Reputation: 32232
This function is now deprecated as it doesn't have an effect anymore.
https://www.php.net/manual/en/function.openssl-free-key.php
PHP 8 deprecates openssl_free_key (actually openssl_pkey_free which it aliases) and automatically destroys the key instance when it goes out of scope.
https://www.php.net/manual/en/function.openssl-pkey-free.php#125655
So really you replace it with nothing, as the resource is now cleaned up properly the same as anything else.
If you want to feel like you're going that extra mile you can call unset()
on it, but that's not a thing I would consider necessary.
Upvotes: 11