Skip to content

Commit 4034dc4

Browse files
authored
Merge pull request #5262 from kenjis/remove-static-for-php81
Remove static variables for PHP 8.1
2 parents b1945a2 + 8d5dc08 commit 4034dc4

File tree

2 files changed

+52
-20
lines changed

2 files changed

+52
-20
lines changed

system/Database/BaseBuilder.php

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,20 @@ class BaseBuilder
244244
'RIGHT OUTER',
245245
];
246246

247+
/**
248+
* Strings that determine if a string represents a literal value or a field name
249+
*
250+
* @var string[]
251+
*/
252+
protected $isLiteralStr = [];
253+
254+
/**
255+
* RegExp used to get operators
256+
*
257+
* @var string[]
258+
*/
259+
protected $pregOperators = [];
260+
247261
/**
248262
* Constructor
249263
*
@@ -2515,13 +2529,11 @@ protected function isLiteral(string $str): bool
25152529
return true;
25162530
}
25172531

2518-
static $_str;
2519-
2520-
if (empty($_str)) {
2521-
$_str = ($this->db->escapeChar !== '"') ? ['"', "'"] : ["'"];
2532+
if ($this->isLiteralStr === []) {
2533+
$this->isLiteralStr = $this->db->escapeChar !== '"' ? ['"', "'"] : ["'"];
25222534
}
25232535

2524-
return in_array($str[0], $_str, true);
2536+
return in_array($str[0], $this->isLiteralStr, true);
25252537
}
25262538

25272539
/**
@@ -2600,7 +2612,10 @@ protected function resetWrite()
26002612
*/
26012613
protected function hasOperator(string $str): bool
26022614
{
2603-
return (bool) preg_match('/(<|>|!|=|\sIS NULL|\sIS NOT NULL|\sEXISTS|\sBETWEEN|\sLIKE|\sIN\s*\(|\s)/i', trim($str));
2615+
return preg_match(
2616+
'/(<|>|!|=|\sIS NULL|\sIS NOT NULL|\sEXISTS|\sBETWEEN|\sLIKE|\sIN\s*\(|\s)/i',
2617+
trim($str)
2618+
) === 1;
26042619
}
26052620

26062621
/**
@@ -2610,11 +2625,11 @@ protected function hasOperator(string $str): bool
26102625
*/
26112626
protected function getOperator(string $str, bool $list = false)
26122627
{
2613-
static $_operators;
2614-
2615-
if (empty($_operators)) {
2616-
$_les = ($this->db->likeEscapeStr !== '') ? '\s+' . preg_quote(trim(sprintf($this->db->likeEscapeStr, $this->db->likeEscapeChar)), '/') : '';
2617-
$_operators = [
2628+
if ($this->pregOperators === []) {
2629+
$_les = $this->db->likeEscapeStr !== ''
2630+
? '\s+' . preg_quote(trim(sprintf($this->db->likeEscapeStr, $this->db->likeEscapeChar)), '/')
2631+
: '';
2632+
$this->pregOperators = [
26182633
'\s*(?:<|>|!)?=\s*', // =, <=, >=, !=
26192634
'\s*<>?\s*', // <, <>
26202635
'\s*>\s*', // >
@@ -2630,7 +2645,11 @@ protected function getOperator(string $str, bool $list = false)
26302645
];
26312646
}
26322647

2633-
return preg_match_all('/' . implode('|', $_operators) . '/i', $str, $match) ? ($list ? $match[0] : $match[0][0]) : false;
2648+
return preg_match_all(
2649+
'/' . implode('|', $this->pregOperators) . '/i',
2650+
$str,
2651+
$match
2652+
) ? ($list ? $match[0] : $match[0][0]) : false;
26342653
}
26352654

26362655
/**

system/Database/BaseConnection.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,13 @@ abstract class BaseConnection implements ConnectionInterface
238238
*/
239239
public $likeEscapeChar = '!';
240240

241+
/**
242+
* RegExp used to escape identifiers
243+
*
244+
* @var array
245+
*/
246+
protected $pregEscapeChar = [];
247+
241248
/**
242249
* Holds previously looked up data
243250
* for performance reasons.
@@ -1119,29 +1126,35 @@ public function escapeIdentifiers($item)
11191126
return $item;
11201127
}
11211128

1122-
static $pregEc = [];
1123-
1124-
if (empty($pregEc)) {
1129+
if ($this->pregEscapeChar === []) {
11251130
if (is_array($this->escapeChar)) {
1126-
$pregEc = [
1131+
$this->pregEscapeChar = [
11271132
preg_quote($this->escapeChar[0], '/'),
11281133
preg_quote($this->escapeChar[1], '/'),
11291134
$this->escapeChar[0],
11301135
$this->escapeChar[1],
11311136
];
11321137
} else {
1133-
$pregEc[0] = $pregEc[1] = preg_quote($this->escapeChar, '/');
1134-
$pregEc[2] = $pregEc[3] = $this->escapeChar;
1138+
$this->pregEscapeChar[0] = $this->pregEscapeChar[1] = preg_quote($this->escapeChar, '/');
1139+
$this->pregEscapeChar[2] = $this->pregEscapeChar[3] = $this->escapeChar;
11351140
}
11361141
}
11371142

11381143
foreach ($this->reservedIdentifiers as $id) {
11391144
if (strpos($item, '.' . $id) !== false) {
1140-
return preg_replace('/' . $pregEc[0] . '?([^' . $pregEc[1] . '\.]+)' . $pregEc[1] . '?\./i', $pregEc[2] . '$1' . $pregEc[3] . '.', $item);
1145+
return preg_replace(
1146+
'/' . $this->pregEscapeChar[0] . '?([^' . $this->pregEscapeChar[1] . '\.]+)' . $this->pregEscapeChar[1] . '?\./i',
1147+
$this->pregEscapeChar[2] . '$1' . $this->pregEscapeChar[3] . '.',
1148+
$item
1149+
);
11411150
}
11421151
}
11431152

1144-
return preg_replace('/' . $pregEc[0] . '?([^' . $pregEc[1] . '\.]+)' . $pregEc[1] . '?(\.)?/i', $pregEc[2] . '$1' . $pregEc[3] . '$2', $item);
1153+
return preg_replace(
1154+
'/' . $this->pregEscapeChar[0] . '?([^' . $this->pregEscapeChar[1] . '\.]+)' . $this->pregEscapeChar[1] . '?(\.)?/i',
1155+
$this->pregEscapeChar[2] . '$1' . $this->pregEscapeChar[3] . '$2',
1156+
$item
1157+
);
11451158
}
11461159

11471160
/**

0 commit comments

Comments
 (0)