PHP Conference Nagoya 2025

openssl_pkey_free

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

openssl_pkey_freeFrees a private key

Warning

This function has been DEPRECATED as of PHP 8.0.0. Relying on this function is highly discouraged.

Description

#[\Deprecated]
openssl_pkey_free(OpenSSLAsymmetricKey $key): void

Note:

This function has no effect. Prior to PHP 8.0.0, this function was used to close the resource.

This function frees a private key created by openssl_pkey_new().

Parameters

key

Resource holding the key.

Return Values

No value is returned.

Changelog

Version Description
8.0.0 This function is now deprecated as it doesn't have an effect anymore.
8.0.0 key accepts an OpenSSLAsymmetricKey now; previously, a resource of type OpenSSL key was accepted.
add a note

User Contributed Notes 2 notes

up
-1
djmaze
5 years ago
This function also frees public key resources as received with openssl_pkey_get_public().

Manual above should say: "Frees a pkey resource"
up
-2
suconghou at gmail dot com
3 years ago
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.
To Top