• Resolved HeavenCore

    (@heavencore)


    On PHP 8.1 this plugin has lots of depreciation notices, (See below).

    People have been reporting this for nearly 6 months now on StackOverflow etc – is there a new version of the plugin on the way to address this?

    Deprecated: Return type of Pantheon_Sessions\Session_Handler::open($save_path, $session_name) should either be compatible with SessionHandlerInterface::open(string $path, string $name): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in C:\WebFarmFiles\wwwroot\foo.com\wp-content\plugins\wp-native-php-sessions\inc\class-session-handler.php on line 26
    
    Deprecated: Return type of Pantheon_Sessions\Session_Handler::close() should either be compatible with SessionHandlerInterface::close(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in C:\WebFarmFiles\wwwroot\foo.com\wp-content\plugins\wp-native-php-sessions\inc\class-session-handler.php on line 117
    
    Deprecated: Return type of Pantheon_Sessions\Session_Handler::read($session_id) should either be compatible with SessionHandlerInterface::read(string $id): string|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in C:\WebFarmFiles\wwwroot\foo.com\wp-content\plugins\wp-native-php-sessions\inc\class-session-handler.php on line 60
    
    Deprecated: Return type of Pantheon_Sessions\Session_Handler::write($session_id, $session_data) should either be compatible with SessionHandlerInterface::write(string $id, string $data): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in C:\WebFarmFiles\wwwroot\foo.com\wp-content\plugins\wp-native-php-sessions\inc\class-session-handler.php on line 37
    
    Deprecated: Return type of Pantheon_Sessions\Session_Handler::destroy($session_id) should either be compatible with SessionHandlerInterface::destroy(string $id): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in C:\WebFarmFiles\wwwroot\foo.com\wp-content\plugins\wp-native-php-sessions\inc\class-session-handler.php on line 82
    
    Deprecated: Return type of Pantheon_Sessions\Session_Handler::gc($maxlifetime) should either be compatible with SessionHandlerInterface::gc(int $max_lifetime): int|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in C:\WebFarmFiles\wwwroot\foo.com\wp-content\plugins\wp-native-php-sessions\inc\class-session-handler.php on line 98
    • This topic was modified 2 years, 3 months ago by HeavenCore.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter HeavenCore

    (@heavencore)

    Proposed fix:

    class-session-handler.php

    <?php
    /**
     * Implementation of 'SessionHandlerInterface' that writes to the database.
     *
     * @package WPNPS
     */
    
    namespace Pantheon_Sessions;
    
    use Pantheon_Sessions\Session;
    
    /**
     * Implementation of 'SessionHandlerInterface' that writes to the database.
     *
     * @package WPNPS
     */
    class Session_Handler implements \SessionHandlerInterface {
    
    	/**
    	 * Closes the session.
    	 *
    	 * @param string $save_path    Path to where the session is to be stored.
    	 * @param string $session_name Name of the session.
    	 * @return boolean
    	 */
    	public function open( $save_path, $session_name ):bool {
    		return true;
    	}
    
    	/**
    	 * Writes a session to the database.
    	 *
    	 * @param string $session_id   Session id.
    	 * @param string $session_data Session data.
    	 * @return boolean
    	 */
    	public function write( $session_id, $session_data ): bool {
    		$session = Session::get_by_sid( $session_id );
    
    		if ( ! $session ) {
    			$session = Session::create_for_sid( $session_id );
    		}
    
    		if ( ! $session ) {
    			trigger_error( 'Could not write session to the database. Please check MySQL configuration.', E_USER_WARNING );
    			return false;
    		}
    
    		$session->set_data( $session_data );
    		return true;
    	}
    
    	/**
    	 * Reads session data from the database.
    	 *
    	 * @param string $session_id Session id.
    	 * @return string
    	 */
    	public function read( $session_id ): string|false {
    		// Handle the case of first time visitors and clients that don't store
    		// cookies (eg. web crawlers).
    		$insecure_session_name = substr( session_name(), 1 );
    		if ( empty( $session_id )
    			|| ( ! isset( $_COOKIE[ session_name() ] ) && ! isset( $_COOKIE[ $insecure_session_name ] ) ) ) {
    			return "";
    		}
    
    		$session = Session::get_by_sid( $session_id );
    		if ( $session ) {
    			return $session->get_data();
    		} else {
    			return false;
    		}
    	}
    
    	/**
    	 * Destroys the session.
    	 *
    	 * @param string $session_id Session id.
    	 */
    	public function destroy( $session_id ): bool {
    		$session = Session::get_by_sid( $session_id );
    		if ( ! $session ) {
    			return true;
    		}
    
    		$session->destroy();
    
    		return true;
    	}
    
    	/**
    	 * Runs the garbage collection process.
    	 *
    	 * @param integer $maxlifetime Maximum lifetime in seconds.
    	 */
    	public function gc( $maxlifetime ): int|false {
    		global $wpdb;
    
    		$wpdb = Session::restore_wpdb_if_null( $wpdb );
    
    		// Be sure to adjust 'php_value session.gc_maxlifetime' to a large enough
    		// value. For example, if you want user sessions to stay in your database
    		// for three weeks before deleting them, you need to set gc_maxlifetime
    		// to '1814400'. At that value, only after a user doesn't log in after
    		// three weeks (1814400 seconds) will his/her session be removed.
    		$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->pantheon_sessions WHERE <code>datetime</code> <= %s ", gmdate( 'Y-m-d H:i:s', time() - $maxlifetime ) ) );
    		return true;
    	}
    
    	/**
    	 * Closes the session.
    	 *
    	 * @return boolean
    	 */
    	public function close(): bool {
    		return true;
    	}
    
    }
    Plugin Contributor Chris Reynolds

    (@jazzs3quence)

    Hi @heavencore

    As noted in the GitHub issue, the deprecation warnings have been silenced with the 1.2.5 release. I have created an issue internally to prioritize a full evaluation for PHP 8.x compatibility to address the underlying issue and proposed solution so we can ensure backwards compatibility with older versions of PHP.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘PHP 8.1 Depreciation Notice (Pantheon_Sessions)’ is closed to new replies.