Skip to content

Commit 8582d97

Browse files
committed
ext/mysqli: Stop using global variable in connection test helper
1 parent 0c21715 commit 8582d97

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

ext/mysqli/tests/connect.inc

+13-12
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,28 @@
1717
$engine = getenv("MYSQL_TEST_ENGINE") ?: "InnoDB";
1818
$socket = getenv("MYSQL_TEST_SOCKET") ?: null;
1919
$skip_on_connect_failure = getenv("MYSQL_TEST_SKIP_CONNECT_FAILURE") ?: true;
20-
$connect_flags = (int)getenv("MYSQL_TEST_CONNECT_FLAGS") ?: 0;
2120
if ($socket) {
2221
ini_set('mysqli.default_socket', $socket);
2322
}
2423

2524
/* Development setting: test experimental features and/or feature requests that never worked before? */
2625
$TEST_EXPERIMENTAL = 1 == getenv("MYSQL_TEST_EXPERIMENTAL");
2726

27+
function get_environment_connection_flags(): int {
28+
static $connect_flags = null;
29+
if ($connect_flags === null) {
30+
$connect_flags = (int)getenv("MYSQL_TEST_CONNECT_FLAGS") ?: 0;
31+
}
32+
return $connect_flags;
33+
}
34+
2835
/**
2936
* Whenever possible, please use this wrapper to make testing of MYSQLI_CLIENT_COMPRESS (and potentially SSL) possible
3037
*
3138
* @param bool $enable_env_flags Enable setting of connection flags through env(MYSQL_TEST_CONNECT_FLAGS)?
3239
*/
3340
function my_mysqli_connect($host, $user, $passwd, $db, $port, $socket, $enable_env_flags = true) {
34-
global $connect_flags;
35-
36-
$flags = $enable_env_flags? $connect_flags:0;
41+
$flags = $enable_env_flags? get_environment_connection_flags():0;
3742
if ($flags !== 0) {
3843
$link = mysqli_init();
3944
if (!mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, $flags))
@@ -51,19 +56,16 @@
5156
* @param bool $enable_env_flags Enable setting of connection flags through env(MYSQL_TEST_CONNECT_FLAGS)
5257
*/
5358
function my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, $flags = 0, $enable_env_flags = true) {
54-
global $connect_flags;
55-
56-
if ($enable_env_flags)
57-
$flags = $flags | $connect_flags;
59+
if ($enable_env_flags) {
60+
$flags = $flags | get_environment_connection_flags();
61+
}
5862

5963
return mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, $flags);
6064
}
6165

6266
class my_mysqli extends mysqli {
6367
public function __construct($host, $user, $passwd, $db, $port, $socket, $enable_env_flags = true) {
64-
global $connect_flags;
65-
66-
$flags = ($enable_env_flags) ? $connect_flags : 0;
68+
$flags = ($enable_env_flags) ? get_environment_connection_flags() : 0;
6769

6870
if ($flags !== 0) {
6971
parent::__construct();
@@ -113,4 +115,3 @@
113115

114116
return true;
115117
}
116-
?>

0 commit comments

Comments
 (0)