Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove static variables for PHP 8.1 #6280

Closed
wants to merge 10 commits into from
20 changes: 19 additions & 1 deletion .github/workflows/test-phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,28 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ '8.1', '8.0', '7.4', '7.3', '7.2', '7.1', '7.0', '5.6', '5.5', '5.4']
php: [ '8.2', '8.1', '8.0', '7.4', '7.3', '7.2', '7.1', '7.0', '5.6', '5.5', '5.4']
DB: [ 'pdo/mysql', 'pdo/pgsql', 'pdo/sqlite', 'mysqli', 'pgsql', 'sqlite' ]
compiler: [ default ]
include:
- php: '8.2'
DB: 'pdo/mysql'
compiler: jit
- php: '8.2'
DB: 'pdo/pgsql'
compiler: jit
- php: '8.2'
DB: 'pdo/sqlite'
compiler: jit
- php: '8.2'
DB: 'mysqli'
compiler: jit
- php: '8.2'
DB: 'pgsql'
compiler: jit
- php: '8.2'
DB: 'sqlite'
compiler: jit
- php: '8.1'
DB: 'pdo/mysql'
compiler: jit
Expand Down
1 change: 1 addition & 0 deletions system/core/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
* @author EllisLab Dev Team
* @link https://codeigniter.com/userguide3/general/controllers.html
*/
#[AllowDynamicProperties]
class CI_Controller {

/**
Expand Down
1 change: 1 addition & 0 deletions system/core/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
* @author EllisLab Dev Team
* @link https://codeigniter.com/userguide3/libraries/loader.html
*/
#[AllowDynamicProperties]
class CI_Loader {

// All these are set automatically. Don't mess with them.
Expand Down
7 changes: 7 additions & 0 deletions system/core/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ class CI_Router {
*/
public $config;

/**
* CI_URI class object
*
* @var object
*/
public $uri;

/**
* List of routes
*
Expand Down
7 changes: 7 additions & 0 deletions system/core/URI.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
*/
class CI_URI {

/**
* CI_Config instance
*
* @var CI_Config
*/
public $config;

/**
* List of cached URI segments
*
Expand Down
45 changes: 32 additions & 13 deletions system/database/DB_driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
* @author EllisLab Dev Team
* @link https://codeigniter.com/userguide3/database/
*/
#[AllowDynamicProperties]
abstract class CI_DB_driver {

/**
Expand Down Expand Up @@ -338,6 +339,20 @@ abstract class CI_DB_driver {
*/
protected $_like_escape_chr = '!';

/**
* RegExp used to escape identifiers
*
* @var array
*/
protected $_preg_escape_char = array();

/**
* RegExp used to get operators
*
* @var string[]
*/
protected $_preg_operators = array();

/**
* ORDER BY random keyword
*
Expand Down Expand Up @@ -1353,13 +1368,11 @@ public function escape_identifiers($item, $split = TRUE)
return $item;
}

static $preg_ec;

if (empty($preg_ec))
if (empty($this->_preg_escape_char))
{
if (is_array($this->_escape_char))
{
$preg_ec = array(
$this->_preg_escape_char = array(
preg_quote($this->_escape_char[0]),
preg_quote($this->_escape_char[1]),
$this->_escape_char[0],
Expand All @@ -1368,22 +1381,30 @@ public function escape_identifiers($item, $split = TRUE)
}
else
{
$preg_ec[0] = $preg_ec[1] = preg_quote($this->_escape_char);
$preg_ec[2] = $preg_ec[3] = $this->_escape_char;
$this->_preg_escape_char[0] = $this->_preg_escape_char[1] = preg_quote($this->_escape_char);
$this->_preg_escape_char[2] = $this->_preg_escape_char[3] = $this->_escape_char;
}
}

foreach ($this->_reserved_identifiers as $id)
{
if (strpos($item, '.'.$id) !== FALSE)
{
return preg_replace('#'.$preg_ec[0].'?([^'.$preg_ec[1].'\.]+)'.$preg_ec[1].'?\.#i', $preg_ec[2].'$1'.$preg_ec[3].'.', $item);
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
);
}
}

$dot = ($split !== FALSE) ? '\.' : '';

return preg_replace('#'.$preg_ec[0].'?([^'.$preg_ec[1].$dot.']+)'.$preg_ec[1].'?(\.)?#i', $preg_ec[2].'$1'.$preg_ec[3].'$2', $item);
return preg_replace(
'#'.$this->_preg_escape_char[0].'?([^'.$this->_preg_escape_char[1].$dot.']+)'.$this->_preg_escape_char[1].'?(\.)?#i',
$this->_preg_escape_char[2].'$1'.$this->_preg_escape_char[3].'$2',
$item
);
}

// --------------------------------------------------------------------
Expand Down Expand Up @@ -1502,14 +1523,12 @@ protected function _has_operator($str)
*/
protected function _get_operator($str)
{
static $_operators;

if (empty($_operators))
if (empty($this->_preg_operators))
{
$_les = ($this->_like_escape_str !== '')
? '\s+'.preg_quote(trim(sprintf($this->_like_escape_str, $this->_like_escape_chr)), '/')
: '';
$_operators = array(
$this->_preg_operators = array(
'\s*(?:<|>|!)?=\s*', // =, <=, >=, !=
'\s*<>?\s*', // <, <>
'\s*>\s*', // >
Expand All @@ -1527,7 +1546,7 @@ protected function _get_operator($str)

}

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

Expand Down
15 changes: 10 additions & 5 deletions system/database/DB_query_builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*/
protected $qb_cache_no_escape = array();

/**
* Strings that determine if a string represents a literal value or a field name
*
* @var string[]
*/
protected $is_literal_str = array();

// --------------------------------------------------------------------

/**
Expand Down Expand Up @@ -2787,15 +2794,13 @@ protected function _is_literal($str)
return TRUE;
}

static $_str;

if (empty($_str))
if (empty($this->is_literal_str))
{
$_str = ($this->_escape_char !== '"')
$this->is_literal_str = ($this->_escape_char !== '"')
? array('"', "'") : array("'");
}

return in_array($str[0], $_str, TRUE);
return in_array($str[0], $this->is_literal_str, TRUE);
}

// --------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion system/database/drivers/postgre/postgre_forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function __construct(&$db)

if (version_compare($this->db->version(), '9.0', '>'))
{
$this->create_table_if = 'CREATE TABLE IF NOT EXISTS';
$this->_create_table_if = 'CREATE TABLE IF NOT EXISTS';
}
}

Expand Down
1 change: 1 addition & 0 deletions system/libraries/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
* @author EllisLab Dev Team
* @link
*/
#[AllowDynamicProperties]
class CI_Driver_Library {

/**
Expand Down
8 changes: 8 additions & 0 deletions system/libraries/Image_lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ class CI_Image_lib {
*/
public $new_image = '';


/**
* Path to destination image
*
* @var string
*/
public $dest_image = '';

/**
* Image width
*
Expand Down
4 changes: 2 additions & 2 deletions system/libraries/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,12 @@ protected function _compile_template()
return;
}

$this->temp = $this->_default_template();
$temp = $this->_default_template();
foreach (array('table_open', 'thead_open', 'thead_close', 'heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', 'tbody_open', 'tbody_close', 'row_start', 'row_end', 'cell_start', 'cell_end', 'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end', 'table_close') as $val)
{
if ( ! isset($this->template[$val]))
{
$this->template[$val] = $this->temp[$val];
$this->template[$val] = $temp[$val];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/codeigniter/core/Loader_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function test_library_config()
// Create library in VFS
$lib = 'unit_test_config_lib';
$class = 'CI_'.ucfirst($lib);
$content = '<?php class '.$class.' { public function __construct($params) { $this->config = $params; } }';
$content = "<?php \n#[AllowDynamicProperties]\nclass ".$class.' { public function __construct($params) { $this->config = $params; } }';
$this->ci_vfs_create(ucfirst($lib), $content, $this->ci_base_root, 'libraries');

// Create config file
Expand Down
7 changes: 4 additions & 3 deletions tests/codeigniter/libraries/Upload_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ function test_data()
$data = array(
'file_name' => 'hello.txt',
'file_type' => 'text/plain',
'file_path' => '/tmp/',
'full_path' => '/tmp/hello.txt',
'raw_name' => 'hello',
'orig_name' => 'hello.txt',
'client_name' => '',
'file_ext' => '.txt',
Expand All @@ -80,6 +77,10 @@ function test_data()
$this->upload->{$k} = $v;
}

$data['file_path'] = '/tmp/';
$data['full_path'] = '/tmp/hello.txt';
$data['raw_name'] = 'hello';

$this->assertEquals('hello.txt', $this->upload->data('file_name'));
$this->assertEquals($data, $this->upload->data());
}
Expand Down
1 change: 1 addition & 0 deletions tests/mocks/ci_testcase.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

#[AllowDynamicProperties]
class CI_TestCase extends \PHPUnit\Framework\TestCase {

public $ci_vfs_root;
Expand Down
Loading