php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36094 session_set_save_handler static methods fail if in object context
Submitted: 2006-01-20 00:03 UTC Modified: 2006-01-20 03:43 UTC
From: levi at alliancesoftware dot com dot au Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.1.2 OS:
Private report: No CVE-ID: None
 [2006-01-20 00:03 UTC] levi at alliancesoftware dot com dot au
Description:
------------
  If you call session_set_save_handler from within a constructor, the engine thinks static callback methods are non-static and gives an E_STRICT error.


 In the code below, if session_set_save_handler() is called from within the constructor, it fails [because $this is still in the local variable table?] but if the constructor calls a static method that then calls session_set_save_handler it succeeds.

Reproduce code:
---------------
<?
error_reporting(E_STRICT);

class SessionHandler
{
    public function __construct()
    {
        // This fails:
        session_set_save_handler(
            array('SessionHandler','open'),
            array('SessionHandler','close'),
            array('SessionHandler','read'),
            array('SessionHandler','write'),
            array('SessionHandler','destroy'),
            array('SessionHandler','gc')
        );

        // This works:
        //SessionHandler::sethandler();
    }

    public static function sethandler() {
        session_set_save_handler(
            array('SessionHandler','open'),
            array('SessionHandler','close'),
            array('SessionHandler','read'),
            array('SessionHandler','write'),
            array('SessionHandler','destroy'),
            array('SessionHandler','gc')
        );
    }

    public static function open($path, $name) { return true; }
    public static function close() { return true; }
    public static function read($id) { return array(); }
    public static function write($id, $data) { return true; }
    public static function destroy($id) { return true; }
    public static function gc($life) { return true; }
}

$x = new SessionHandler();

session_start();

?>

Expected result:
----------------
Nothing

Actual result:
--------------
Strict Standards: Non-static method SessionHandler::open() cannot be called statically, assuming $this from compatible context SessionHandler in /home/levi/public_html/tS.php5 on line 22

Strict Standards: Non-static method SessionHandler::close() cannot be called statically, assuming $this from compatible context SessionHandler in /home/levi/public_html/tS.php5 on line 22

... etc ...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-20 00:21 UTC] sniper@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 [2006-01-20 03:43 UTC] levi at alliancesoftware dot com dot au
I beg to differ, it **is** a bug, but is not to do with session_set_save_handler: it's triggered by every static member callback function from within a non-static context.

Fixed in 5.1.3CVS: See bug #36011
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Fri Jul 17 23:00:01 2026 UTC