PHP: openssl_pkey_new()

Note to self:

When generating a new private key using openssl_pkey_new(), and specifying the private_key_bits parameter as a variable.

Be sure to cast the variable to an integer!

e.g.

$keysize = "2048";
$privateKey = openssl_pkey_new(array(
    'private_key_bits' => $keysize, // ---> This won't work
    'private_key_bits' => (int)$keysize, // ---> Correct
    'private_key_bits' => 2048, // ---> Also correct.
    'private_key_type' => OPENSSL_KEYTYPE_RSA,
));