PHPSessionHandler: Drop now-pointless return methods for PHP5 compat.
authorJames D. Forrester <jforrester@wikimedia.org>
Thu, 24 May 2018 18:16:21 +0000 (11:16 -0700)
committerJames D. Forrester <jforrester@wikimedia.org>
Thu, 31 May 2018 01:03:44 +0000 (18:03 -0700)
Change-Id: I8c3a4d12a34407f29764adb010f91dc870e715d7

RELEASE-NOTES-1.32
includes/session/PHPSessionHandler.php

index 3d193d4..13d15c2 100644 (file)
@@ -126,6 +126,9 @@ because of Phabricator reports.
 * (T140807) The wgResourceLoaderLESSImportPaths configuration option was removed
   from ResourceLoader. Instead, use `@import` statements in LESS to import
   files directly from nearby directories within the same project.
+* The protected methods PHPSessionHandler::returnSuccess() and returnFailure(),
+  only needed for PHP5 compatibility, have been removed. It now uses the boolean
+  values `true` and `false` respectively.
 
 === Deprecations in 1.32 ===
 * Use of a StartProfiler.php file is deprecated in favour of placing
index b76f0ff..4e1a69b 100644 (file)
@@ -162,39 +162,12 @@ class PHPSessionHandler implements \SessionHandlerInterface {
                }
        }
 
-       /**
-        * Workaround for PHP5 bug
-        *
-        * PHP5 has a bug in handling boolean return values for
-        * SessionHandlerInterface methods, it expects 0 or -1 instead of true or
-        * false. See <https://wiki.php.net/rfc/session.user.return-value>.
-        *
-        * PHP7 and HHVM are not affected.
-        *
-        * @todo When we drop support for Zend PHP 5, this can be removed.
-        * @return bool|int
-        * @codeCoverageIgnore
-        */
-       protected static function returnSuccess() {
-               return defined( 'HHVM_VERSION' ) || version_compare( PHP_VERSION, '7.0.0', '>=' ) ? true : 0;
-       }
-
-       /**
-        * Workaround for PHP5 bug
-        * @see self::returnSuccess()
-        * @return bool|int
-        * @codeCoverageIgnore
-        */
-       protected static function returnFailure() {
-               return defined( 'HHVM_VERSION' ) || version_compare( PHP_VERSION, '7.0.0', '>=' ) ? false : -1;
-       }
-
        /**
         * Initialize the session (handler)
         * @private For internal use only
         * @param string $save_path Path used to store session files (ignored)
         * @param string $session_name Session name (ignored)
-        * @return bool|int Success (see self::returnSuccess())
+        * @return true
         */
        public function open( $save_path, $session_name ) {
                if ( self::$instance !== $this ) {
@@ -203,20 +176,20 @@ class PHPSessionHandler implements \SessionHandlerInterface {
                if ( !$this->enable ) {
                        throw new \BadMethodCallException( 'Attempt to use PHP session management' );
                }
-               return self::returnSuccess();
+               return true;
        }
 
        /**
         * Close the session (handler)
         * @private For internal use only
-        * @return bool|int Success (see self::returnSuccess())
+        * @return true
         */
        public function close() {
                if ( self::$instance !== $this ) {
                        throw new \UnexpectedValueException( __METHOD__ . ': Wrong instance called!' );
                }
                $this->sessionFieldCache = [];
-               return self::returnSuccess();
+               return true;
        }
 
        /**
@@ -251,7 +224,7 @@ class PHPSessionHandler implements \SessionHandlerInterface {
         * @param string $dataStr Session data. Not that you should ever call this
         *   directly, but note that this has the same issues with code injection
         *   via user-controlled data as does PHP's unserialize function.
-        * @return bool|int Success (see self::returnSuccess())
+        * @return bool
         */
        public function write( $id, $dataStr ) {
                if ( self::$instance !== $this ) {
@@ -270,14 +243,14 @@ class PHPSessionHandler implements \SessionHandlerInterface {
                                [
                                        'session' => $id,
                        ] );
-                       return self::returnSuccess();
+                       return true;
                }
 
                // First, decode the string PHP handed us
                $data = \Wikimedia\PhpSessionSerializer::decode( $dataStr );
                if ( $data === null ) {
                        // @codeCoverageIgnoreStart
-                       return self::returnFailure();
+                       return false;
                        // @codeCoverageIgnoreEnd
                }
 
@@ -350,14 +323,14 @@ class PHPSessionHandler implements \SessionHandlerInterface {
 
                $session->persist();
 
-               return self::returnSuccess();
+               return true;
        }
 
        /**
         * Destroy a session
         * @private For internal use only
         * @param string $id Session id
-        * @return bool|int Success (see self::returnSuccess())
+        * @return true
         */
        public function destroy( $id ) {
                if ( self::$instance !== $this ) {
@@ -370,14 +343,14 @@ class PHPSessionHandler implements \SessionHandlerInterface {
                if ( $session ) {
                        $session->clear();
                }
-               return self::returnSuccess();
+               return true;
        }
 
        /**
         * Execute garbage collection.
         * @private For internal use only
         * @param int $maxlifetime Maximum session life time (ignored)
-        * @return bool|int Success (see self::returnSuccess())
+        * @return true
         * @codeCoverageIgnore See T135576
         */
        public function gc( $maxlifetime ) {
@@ -386,6 +359,6 @@ class PHPSessionHandler implements \SessionHandlerInterface {
                }
                $before = date( 'YmdHis', time() );
                $this->store->deleteObjectsExpiringBefore( $before );
-               return self::returnSuccess();
+               return true;
        }
 }