Update random_bytes() to conform to PHP7.0.0-RC3

Fixes #843
This commit is contained in:
Scott 2015-10-09 15:19:59 -04:00 committed by terrafrost
parent 4a3e07a57d
commit d899b7988d

View File

@ -55,9 +55,10 @@ class Random
{ {
if (version_compare(PHP_VERSION, '7.0.0', '>=')) { if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
try { try {
return random_bytes($length); return \random_bytes($length);
} catch (\Error $e) { } catch (\Throwable $e) {
// If a sufficient source of randomness is unavailable, random_bytes() will emit a warning. // If a sufficient source of randomness is unavailable, random_bytes() will throw an
// object that implements the Throwable interface (Exception, TypeError, Error).
// We don't actually need to do anything here. The string() method should just continue // We don't actually need to do anything here. The string() method should just continue
// as normal. Note, however, that if we don't have a sufficient source of randomness for // as normal. Note, however, that if we don't have a sufficient source of randomness for
// random_bytes(), most of the other calls here will fail too, so we'll end up using // random_bytes(), most of the other calls here will fail too, so we'll end up using