8000 Update random includes. · phpredis/phpredis@a51215c · GitHub
[go: up one dir, main page]

Skip to content

Commit a51215c

Browse files
Update random includes.
PHP 8.4 has some breaking changes with respect to where PHP's random methods and helpers are. This commit fixes those issues while staying backward compatible. Fixes #2463
1 parent 2612d44 commit a51215c

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

backoff.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#include "common.h"
22

3+
#if PHP_VERSION_ID < 80400
34
#include <ext/standard/php_rand.h>
4-
5-
#if PHP_VERSION_ID >= 70100
6-
#include <ext/standard/php_mt_rand.h>
75
#else
6+
#include <ext/random/php_random.h>
7+
#endif
8+
9+
#if PHP_VERSION_ID < 70100
810
static zend_long php_mt_rand_range(zend_long min, zend_long max) {
9-
zend_long number = php_rand();
10-
RAND_RANGE(number, min, max, PHP_RAND_MAX);
11-
return number;
11+
return min + php_rand() % (max - min + 1)
1212
}
1313
#endif
1414

library.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,14 @@
5656
#include <ext/json/php_json.h>
5757
#endif
5858

59-
#include <ext/standard/php_rand.h>
6059
#include <ext/hash/php_hash.h>
6160

61+
#if PHP_VERSION_ID < 80400
62+
#include <ext/standard/php_rand.h>
63+
#else
64+
#include <ext/random/php_random.h>
65+
#endif
66+
6267
#define UNSERIALIZE_NONE 0
6368
#define UNSERIALIZE_KEYS 1
6469
#define UNSERIALIZE_VALS 2

redis.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@
2727
#include "redis_cluster.h"
2828
#include "redis_commands.h"
2929
#include "redis_sentinel.h"
30-
#include <standard/php_random.h>
3130
#include <ext/spl/spl_exceptions.h>
3231
#include <zend_exceptions.h>
3332
#include <ext/standard/info.h>
3433
#include <ext/hash/php_hash.h>
3534

35+
#if PHP_VERSION_ID < 80400
36+
#include <ext/standard/php_random.h>
37+
#else
38+
#include <ext/random/php_random.h>
39+
#endif
3640

3741
#ifdef PHP_SESSION
3842
#include <ext/session/php_session.h>

0 commit comments

Comments
 (0)
0