From 02818c441cb10ce6bec2bc673fefdf1513791dc3 Mon Sep 17 00:00:00 2001 From: Ricordisamoa Date: Wed, 10 Feb 2016 18:07:30 +0100 Subject: [PATCH] Stop doing $that = $this in includes/db Closures support $this as of PHP 5.4 Also made DatabaseBase::indexName() protected Change-Id: Iff31e7d9186832a855a953b923ac182f1c66ffa0 --- includes/db/Database.php | 23 +++++++++-------------- includes/db/DatabaseMysqlBase.php | 5 ++--- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/includes/db/Database.php b/includes/db/Database.php index a4d0ad0532..564cd2ee24 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -1929,10 +1929,7 @@ abstract class DatabaseBase implements IDatabase { * @param string $index * @return string */ - public function indexName( $index ) { - // @FIXME: Make this protected once we move away from PHP 5.3 - // Needs to be public because of usage in closure (in DatabaseBase::replaceVars) - + protected function indexName( $index ) { // Backwards-compatibility hack $renamed = array( 'ar_usertext_timestamp' => 'usertext_timestamp', @@ -3100,7 +3097,6 @@ abstract class DatabaseBase implements IDatabase { * @return string The new SQL statement with variables replaced */ protected function replaceVars( $ins ) { - $that = $this; $vars = $this->getSchemaVars(); return preg_replace_callback( '! @@ -3109,19 +3105,19 @@ abstract class DatabaseBase implements IDatabase { `\{\$ (\w+) }` | # 4. addIdentifierQuotes /\*\$ (\w+) \*/ # 5. leave unencoded !x', - function ( $m ) use ( $that, $vars ) { + function ( $m ) use ( $vars ) { // Note: Because of , // check for both nonexistent keys *and* the empty string. if ( isset( $m[1] ) && $m[1] !== '' ) { if ( $m[1] === 'i' ) { - return $that->indexName( $m[2] ); + return $this->indexName( $m[2] ); } else { - return $that->tableName( $m[2] ); + return $this->tableName( $m[2] ); } } elseif ( isset( $m[3] ) && $m[3] !== '' && array_key_exists( $m[3], $vars ) ) { - return $that->addQuotes( $vars[$m[3]] ); + return $this->addQuotes( $vars[$m[3]] ); } elseif ( isset( $m[4] ) && $m[4] !== '' && array_key_exists( $m[4], $vars ) ) { - return $that->addIdentifierQuotes( $vars[$m[4]] ); + return $this->addIdentifierQuotes( $vars[$m[4]] ); } elseif ( isset( $m[5] ) && $m[5] !== '' && array_key_exists( $m[5], $vars ) ) { return $vars[$m[5]]; } else { @@ -3179,10 +3175,9 @@ abstract class DatabaseBase implements IDatabase { return null; } - $that = $this; - $unlocker = new ScopedCallback( function () use ( $that, $lockKey, $fname ) { - $that->commit( __METHOD__, 'flush' ); - $that->unlock( $lockKey, $fname ); + $unlocker = new ScopedCallback( function () use ( $lockKey, $fname ) { + $this->commit( __METHOD__, 'flush' ); + $this->unlock( $lockKey, $fname ); } ); $this->commit( __METHOD__, 'flush' ); diff --git a/includes/db/DatabaseMysqlBase.php b/includes/db/DatabaseMysqlBase.php index 29106abedd..c5aafea6e9 100644 --- a/includes/db/DatabaseMysqlBase.php +++ b/includes/db/DatabaseMysqlBase.php @@ -692,17 +692,16 @@ abstract class DatabaseMysqlBase extends Database { $this->getLBInfo( 'clusterMasterHost' ) ?: $this->getServer() ); - $that = $this; return $cache->getWithSetCallback( $key, $cache::TTL_INDEFINITE, - function () use ( $that, $cache, $key ) { + function () use ( $cache, $key ) { // Get and leave a lock key in place for a short period if ( !$cache->lock( $key, 0, 10 ) ) { return false; // avoid master connection spike slams } - $conn = $that->getLazyMasterHandle(); + $conn = $this->getLazyMasterHandle(); if ( !$conn ) { return false; // something is misconfigured } -- 2.20.1