From f0a9b332445977cfb05fee2dacc02667946a9cd2 Mon Sep 17 00:00:00 2001
From: Derek Jones
Date: Wed, 29 Jul 2009 14:19:18 +0000
Subject: PHP 5.3.0 compatibility changes
---
system/codeigniter/CodeIgniter.php | 6 +++---
system/codeigniter/Common.php | 24 +++++++++++++++++++++---
system/database/DB.php | 2 +-
system/libraries/Loader.php | 2 +-
system/libraries/Profiler.php | 4 ++--
system/libraries/URI.php | 4 +++-
user_guide/changelog.html | 1 +
7 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php
index 68f6c759e..b78736a04 100644
--- a/system/codeigniter/CodeIgniter.php
+++ b/system/codeigniter/CodeIgniter.php
@@ -56,8 +56,8 @@ require(APPPATH.'config/constants'.EXT);
* Define a custom error handler so we can log PHP errors
* ------------------------------------------------------
*/
-set_error_handler('_exception_handler');
-set_magic_quotes_runtime(0); // Kill magic quotes
+//set_error_handler('_exception_handler');
+@set_magic_quotes_runtime(0); // Kill magic quotes
/*
* ------------------------------------------------------
@@ -130,7 +130,7 @@ $LANG =& load_class('Language');
* Note: The Loader class needs to be included first
*
*/
-if (floor(phpversion()) < 5)
+if ( ! is_php(5))
{
load_class('Loader', FALSE);
require(BASEPATH.'codeigniter/Base4'.EXT);
diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php
index f45c85c26..1ffed6a0c 100644
--- a/system/codeigniter/Common.php
+++ b/system/codeigniter/Common.php
@@ -150,16 +150,34 @@ function &load_class($class, $instantiate = TRUE)
if ($is_subclass == TRUE)
{
$name = config_item('subclass_prefix').$class;
- $objects[$class] =& new $name();
+
+ $objects[$class] =& instantiate_class(new $name());
return $objects[$class];
}
$name = ($class != 'Controller') ? 'CI_'.$class : $class;
-
- $objects[$class] =& new $name();
+
+ $objects[$class] =& instantiate_class(new $name());
return $objects[$class];
}
+/**
+ * Instantiate Class
+ *
+ * Returns a new class object by reference, used by load_class() and the DB class.
+ * Required to retain PHP 4 compatibility and also not make PHP 5.3 cry.
+ *
+ * Use: $obj =& instantiate_class(new Foo());
+ *
+ * @access public
+ * @param object
+ * @return object
+ */
+function &instantiate_class(&$class_object)
+{
+ return $class_object;
+}
+
/**
* Loads the main config.php file
*
diff --git a/system/database/DB.php b/system/database/DB.php
index efe1d388a..0f734d748 100644
--- a/system/database/DB.php
+++ b/system/database/DB.php
@@ -130,7 +130,7 @@ function &DB($params = '', $active_record_override = FALSE)
// Instantiate the DB adapter
$driver = 'CI_DB_'.$params['dbdriver'].'_driver';
- $DB =& new $driver($params);
+ $DB =& instantiate_class(new $driver($params));
if ($DB->autoinit == TRUE)
{
diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php
index d615a1363..781c83c65 100644
--- a/system/libraries/Loader.php
+++ b/system/libraries/Loader.php
@@ -252,7 +252,7 @@ class CI_Loader {
require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility'.EXT);
$class = 'CI_DB_'.$CI->db->dbdriver.'_utility';
- $CI->dbutil =& new $class();
+ $CI->dbutil =& instantiate_class(new $class());
$CI->load->_ci_assign_to_models();
}
diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php
index 98cec0653..ecd0e708d 100644
--- a/system/libraries/Profiler.php
+++ b/system/libraries/Profiler.php
@@ -103,11 +103,11 @@ class CI_Profiler {
function _compile_queries()
{
$dbs = array();
-
+
// Let's determine which databases are currently connected to
foreach (get_object_vars($this->CI) as $CI_object)
{
- if ( is_subclass_of(get_class($CI_object), 'CI_DB') )
+ if (is_object($CI_object) && is_subclass_of(get_class($CI_object), 'CI_DB') )
{
$dbs[] = $CI_object;
}
diff --git a/system/libraries/URI.php b/system/libraries/URI.php
index efc7a18b3..68b678053 100644
--- a/system/libraries/URI.php
+++ b/system/libraries/URI.php
@@ -186,7 +186,9 @@ class CI_URI {
{
if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE)
{
- if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str))
+ // preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards
+ // compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern
+ if ( ! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|i", $str))
{
show_error('The URI you submitted has disallowed characters.', 400);
}
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index 354652fd0..61a028049 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -90,6 +90,7 @@ SVN Revision:
General