Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Remove deprecated notice in PHP7.1, 7.2 #1087

Open
wants to merge 2 commits into
base: 5.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,20 @@ class McryptPseudoRandomStringGenerator implements PseudoRandomStringGeneratorIn
*/
public function __construct()
{
if (!function_exists('mcrypt_create_iv')) {
throw new FacebookSDKException(
static::ERROR_MESSAGE .
'The function mcrypt_create_iv() does not exist.'
);
if (version_compare( PHP_VERSION, '7.1', '>=' )) {
if (!function_exists('random_bytes')) {
throw new FacebookSDKException(
static::ERROR_MESSAGE .
'The function random_bytes() does not exist.'
);
}
} else {
if (!function_exists('mcrypt_create_iv')) {
throw new FacebookSDKException(
static::ERROR_MESSAGE .
'The function mcrypt_create_iv() does not exist.'
);
}
}
}

Expand All @@ -54,12 +63,16 @@ public function getPseudoRandomString($length)
{
$this->validateLength($length);

$binaryString = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
if (version_compare( PHP_VERSION, '7.1', '>=' )) {
$binaryString = random_bytes($length);
} else {
$binaryString = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
}

if ($binaryString === false) {
throw new FacebookSDKException(
static::ERROR_MESSAGE .
'mcrypt_create_iv() returned an error.'
'mcrypt_create_iv() or random_bytes() returned an error.'
);
}

Expand Down