Skip to content

Commit

Permalink
Cache API: Remove WP_Object_Cache::__destruct() and `wpdb::__destru…
Browse files Browse the repository at this point in the history
…ct()`.

Originally added in [4686], these constructor/destructor pairings were designed to prevent the objects from being destroyed before shutdown, when output buffers are flushed.

A deeper investigation reveals that this approach didn't quite work as expected and was later made redundant by introducing `wp_ob_end_flush_all()` in [5462].

Props wonderboymusic, nacin, Mte90, SergeyBiryukov.
Fixes #21402.

git-svn-id: https://develop.svn.wordpress.org/trunk@47107 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Jan 23, 2020
1 parent 1c006d7 commit e730334
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 42 deletions.
39 changes: 10 additions & 29 deletions src/wp-includes/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,16 @@ class WP_Object_Cache {
*/
private $multisite;

/**
* Sets up object properties; PHP 5 style constructor.
*
* @since 2.0.8
*/
public function __construct() {
$this->multisite = is_multisite();
$this->blog_prefix = $this->multisite ? get_current_blog_id() . ':' : '';
}

/**
* Makes private properties readable for backward compatibility.
*
Expand Down Expand Up @@ -726,33 +736,4 @@ public function switch_to_blog( $blog_id ) {
protected function _exists( $key, $group ) {
return isset( $this->cache[ $group ] ) && ( isset( $this->cache[ $group ][ $key ] ) || array_key_exists( $key, $this->cache[ $group ] ) );
}

/**
* Sets up object properties; PHP 5 style constructor.
*
* @since 2.0.8
*/
public function __construct() {
$this->multisite = is_multisite();
$this->blog_prefix = $this->multisite ? get_current_blog_id() . ':' : '';

/**
* @todo This should be moved to the PHP4 style constructor, PHP5
* already calls __destruct()
*/
register_shutdown_function( array( $this, '__destruct' ) );
}

/**
* Saves the object cache before object is completely destroyed.
*
* Called upon object destruction, which should be when PHP ends.
*
* @since 2.0.8
*
* @return true Always returns true.
*/
public function __destruct() {
return true;
}
}
13 changes: 0 additions & 13 deletions src/wp-includes/wp-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,6 @@ class wpdb {
* @param string $dbhost MySQL database host
*/
public function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) {
register_shutdown_function( array( $this, '__destruct' ) );

if ( WP_DEBUG && WP_DEBUG_DISPLAY ) {
$this->show_errors();
}
Expand All @@ -632,17 +630,6 @@ public function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) {
$this->db_connect();
}

/**
* PHP5 style destructor and will run when database object is destroyed.
*
* @see wpdb::__construct()
* @since 2.0.8
* @return true
*/
public function __destruct() {
return true;
}

/**
* Makes private properties readable for backward compatibility.
*
Expand Down

0 comments on commit e730334

Please sign in to comment.