diff --git a/ext/random/randomizer.c b/ext/random/randomizer.c index 41be98d266c..c94c9449db9 100644 --- a/ext/random/randomizer.c +++ b/ext/random/randomizer.c @@ -24,7 +24,6 @@ #include "ext/standard/php_array.h" #include "ext/standard/php_string.h" -#include "ext/spl/spl_exceptions.h" #include "Zend/zend_exceptions.h" static inline void randomizer_common_init(php_random_randomizer *randomizer, zend_object *engine_object) { @@ -102,7 +101,7 @@ PHP_METHOD(Random_Randomizer, nextInt) RETURN_THROWS(); } if (randomizer->status->last_generated_size > sizeof(zend_long)) { - zend_throw_exception(spl_ce_RuntimeException, "Generated value exceeds size of int", 0); + zend_throw_exception(random_ce_Random_RandomException, "Generated value exceeds size of int", 0); RETURN_THROWS(); } diff --git a/ext/random/tests/03_randomizer/basic.phpt b/ext/random/tests/03_randomizer/basic.phpt index 077b9f5b780..a2f6378a71e 100644 --- a/ext/random/tests/03_randomizer/basic.phpt +++ b/ext/random/tests/03_randomizer/basic.phpt @@ -31,7 +31,7 @@ foreach ($engines as $engine) { for ($i = 0; $i < 1000; $i++) { try { $randomizer->nextInt(); - } catch (\RuntimeException $e) { + } catch (\Random\RandomException $e) { if ($e->getMessage() !== 'Generated value exceeds size of int') { die($engine::class . ": nextInt: failure: {$e->getMessage()}"); } diff --git a/ext/random/tests/03_randomizer/compatibility_user.phpt b/ext/random/tests/03_randomizer/compatibility_user.phpt index 8336e7d569b..3b4251aecbe 100644 --- a/ext/random/tests/03_randomizer/compatibility_user.phpt +++ b/ext/random/tests/03_randomizer/compatibility_user.phpt @@ -42,7 +42,7 @@ try { die("failure PcgOneseq128XslRr64 i: {$i} native: {$native} user: {$user}"); } } -} catch (\RuntimeException $e) { +} catch (\Random\RandomException $e) { if ($e->getMessage() !== 'Generated value exceeds size of int') { throw $e; } @@ -68,7 +68,7 @@ try { die("failure Xoshiro256StarStar i: {$i} native: {$native} user: {$user}"); } } -} catch (\RuntimeException $e) { +} catch (\Random\RandomException $e) { if ($e->getMessage() !== 'Generated value exceeds size of int') { throw $e; } diff --git a/ext/random/tests/03_randomizer/nextint_error.phpt b/ext/random/tests/03_randomizer/nextint_error.phpt new file mode 100644 index 00000000000..5f9f8bdc77c --- /dev/null +++ b/ext/random/tests/03_randomizer/nextint_error.phpt @@ -0,0 +1,18 @@ +--TEST-- +Random: Randomizer: nextInt() throws for too large values on 32 Bit +--SKIPIF-- + +--FILE-- +nextInt()); +} catch (\Random\RandomException $e) { + echo $e->getMessage(), PHP_EOL; +} + +?> +--EXPECT-- +Generated value exceeds size of int