From 4d2ab530cb2f275e1e235143759d0f25cd9dc0a3 Mon Sep 17 00:00:00 2001 From: ryan Date: Sat, 6 Jan 2007 23:36:51 +0000 Subject: [PATCH] Fiddle with object destruction and shutdown. Curses upon php 5.2. fixes #3354 git-svn-id: http://svn.automattic.com/wordpress/trunk@4686 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/cache.php | 13 +++++++++++++ wp-includes/wp-db.php | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/wp-includes/cache.php b/wp-includes/cache.php index 2c6a14d14b..09ca7cda77 100644 --- a/wp-includes/cache.php +++ b/wp-includes/cache.php @@ -8,6 +8,8 @@ function wp_cache_add($key, $data, $flag = '', $expire = 0) { function wp_cache_close() { global $wp_object_cache; + if ( ! isset($wp_object_cache) ) + return; return $wp_object_cache->save(); } @@ -392,8 +394,14 @@ class WP_Object_Cache { } function WP_Object_Cache() { + return $this->__construct(); + } + + function __construct() { global $blog_id; + register_shutdown_function(array(&$this, "__destruct")); + if (defined('DISABLE_CACHE')) return; @@ -428,5 +436,10 @@ class WP_Object_Cache { $this->blog_id = $this->hash($blog_id); } + + function __destruct() { + $this->save(); + return true; + } } ?> diff --git a/wp-includes/wp-db.php b/wp-includes/wp-db.php index 8d727bdf98..9e6648a953 100644 --- a/wp-includes/wp-db.php +++ b/wp-includes/wp-db.php @@ -44,6 +44,12 @@ class wpdb { * @param string $dbhost */ function wpdb($dbuser, $dbpassword, $dbname, $dbhost) { + return $this->__construct($dbuser, $dbpassword, $dbname, $dbhost); + } + + function __construct($dbuser, $dbpassword, $dbname, $dbhost) { + register_shutdown_function(array(&$this, "__destruct")); + $this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword); if (!$this->dbh) { $this->bail(" @@ -61,6 +67,10 @@ class wpdb { $this->select($dbname); } + function __destruct() { + return true; + } + /** * Selects a database using the current class's $this->dbh * @param string $db name