Skip to content

Commit 6b20273

Browse files
committed
Fix usage of static variables
1 parent 757829f commit 6b20273

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

system/database/DB_driver.php

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,20 @@ abstract class CI_DB_driver {
339339
*/
340340
protected $_like_escape_chr = '!';
341341

342+
/**
343+
* RegExp used to escape identifiers
344+
*
345+
* @var array
346+
*/
347+
protected $_preg_escape_char = array();
348+
349+
/**
350+
* RegExp used to get operators
351+
*
352+
* @var string[]
353+
*/
354+
protected $_preg_operators = array();
355+
342356
/**
343357
* ORDER BY random keyword
344358
*
@@ -1415,13 +1429,11 @@ public function escape_identifiers($item)
14151429
return $item;
14161430
}
14171431

1418-
static $preg_ec = array();
1419-
1420-
if (empty($preg_ec))
1432+
if (empty($this->_preg_escape_char))
14211433
{
14221434
if (is_array($this->_escape_char))
14231435
{
1424-
$preg_ec = array(
1436+
$this->_preg_escape_char = array(
14251437
preg_quote($this->_escape_char[0], '/'),
14261438
preg_quote($this->_escape_char[1], '/'),
14271439
$this->_escape_char[0],
@@ -1430,20 +1442,20 @@ public function escape_identifiers($item)
14301442
}
14311443
else
14321444
{
1433-
$preg_ec[0] = $preg_ec[1] = preg_quote($this->_escape_char, '/');
1434-
$preg_ec[2] = $preg_ec[3] = $this->_escape_char;
1445+
$this->_preg_escape_char[0] = $this->_preg_escape_char[1] = preg_quote($this->_escape_char, '/');
1446+
$this->_preg_escape_char[2] = $this->_preg_escape_char[3] = $this->_escape_char;
14351447
}
14361448
}
14371449

14381450
foreach ($this->_reserved_identifiers as $id)
14391451
{
14401452
if (strpos($item, '.'.$id) !== FALSE)
14411453
{
1442-
return preg_replace('/'.$preg_ec[0].'?([^'.$preg_ec[1].'\.]+)'.$preg_ec[1].'?\./i', $preg_ec[2].'$1'.$preg_ec[3].'.', $item);
1454+
return preg_replace('/'.$this->_preg_escape_char[0].'?([^'.$this->_preg_escape_char[1].'\.]+)'.$this->_preg_escape_char[1].'?\./i', $this->_preg_escape_char[2].'$1'.$this->_preg_escape_char[3].'.', $item);
14431455
}
14441456
}
14451457

1446-
return preg_replace('/'.$preg_ec[0].'?([^'.$preg_ec[1].'\.]+)'.$preg_ec[1].'?(\.)?/i', $preg_ec[2].'$1'.$preg_ec[3].'$2', $item);
1458+
return preg_replace('/'.$this->_preg_escape_char[0].'?([^'.$this->_preg_escape_char[1].'\.]+)'.$this->_preg_escape_char[1].'?(\.)?/i', $this->_preg_escape_char[2].'$1'.$this->_preg_escape_char[3].'$2', $item);
14471459
}
14481460

14491461
// --------------------------------------------------------------------
@@ -1562,14 +1574,12 @@ protected function _has_operator($str)
15621574
*/
15631575
protected function _get_operator($str)
15641576
{
1565-
static $_operators;
1566-
1567-
if (empty($_operators))
1577+
if (empty($this->_preg_operators))
15681578
{
15691579
$_les = ($this->_like_escape_str !== '')
15701580
? '\s+'.preg_quote(trim(sprintf($this->_like_escape_str, $this->_like_escape_chr)), '/')
15711581
: '';
1572-
$_operators = array(
1582+
$this->_preg_operators = array(
15731583
'\s*(?:<|>|!)?=\s*', // =, <=, >=, !=
15741584
'\s*<>?\s*', // <, <>
15751585
'\s*>\s*', // >
@@ -1587,7 +1597,7 @@ protected function _get_operator($str)
15871597

15881598
}
15891599

1590-
return preg_match('/'.implode('|', $_operators).'/i', $str, $match)
1600+
return preg_match('/'.implode('|', $this->_preg_operators).'/i', $str, $match)
15911601
? $match[0] : FALSE;
15921602
}
15931603

system/database/DB_query_builder.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
271271
*/
272272
protected $qb_cache_no_escape = array();
273273

274+
/**
275+
* Strings that determine if a string represents a literal value or a field name
276+
*
277+
* @var string[]
278+
*/
279+
protected $is_literal_str = array();
280+
274281
// --------------------------------------------------------------------
275282

276283
/**
@@ -2715,15 +2722,13 @@ protected function _is_literal($str)
27152722
return TRUE;
27162723
}
27172724

2718-
static $_str;
2719-
2720-
if (empty($_str))
2725+
if (empty($this->is_literal_str))
27212726
{
2722-
$_str = ($this->_escape_char !== '"')
2727+
$this->is_literal_str = ($this->_escape_char !== '"')
27232728
? array('"', "'") : array("'");
27242729
}
27252730

2726-
return in_array($str[0], $_str, TRUE);
2731+
return in_array($str[0], $this->is_literal_str, TRUE);
27272732
}
27282733

27292734
// --------------------------------------------------------------------

0 commit comments

Comments
 (0)