BagOStuff: Don't try to access a protected variable in a closure
authorKunal Mehta <legoktm@gmail.com>
Sun, 23 Aug 2015 22:31:36 +0000 (15:31 -0700)
committerKunal Mehta <legoktm@gmail.com>
Sun, 23 Aug 2015 22:31:36 +0000 (15:31 -0700)
Follows up 78f1fee5593781b.

Change-Id: Id356509cc55a5953351dfd98896cf01055739ee0

includes/libs/objectcache/BagOStuff.php

index 83e0153..5004a8a 100644 (file)
@@ -289,13 +289,15 @@ abstract class BagOStuff implements LoggerAwareInterface {
                }
 
                $lSince = microtime( true ); // lock timestamp
+               // PHP 5.3: Can't use $this in a closure
                $that = $this;
+               $logger = $this->logger;
 
-               return new ScopedCallback( function() use ( $that, $key, $lSince, $expiry ) {
+               return new ScopedCallback( function() use ( $that, $logger, $key, $lSince, $expiry ) {
                        $latency = .050; // latency skew (err towards keeping lock present)
                        $age = ( microtime( true ) - $lSince + $latency );
                        if ( ( $age + $latency ) >= $expiry ) {
-                               $that->logger->warning( "Lock for $key held too long ($age sec)." );
+                               $logger->warning( "Lock for $key held too long ($age sec)." );
                                return; // expired; it's not "safe" to delete the key
                        }
                        $that->unlock( $key );