From:             levi at alliancesoftware dot com dot au
Operating system: 
PHP version:      5.1.2
PHP Bug Type:     Scripting Engine problem
Bug description:  session_set_save_handler static methods fail if in object 
context

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 ...

-- 
Edit bug report at http://bugs.php.net/?id=36094&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=36094&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): 
http://bugs.php.net/fix.php?id=36094&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=36094&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=36094&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=36094&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=36094&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=36094&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=36094&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=36094&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=36094&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=36094&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=36094&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=36094&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=36094&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=36094&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=36094&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=36094&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=36094&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=36094&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=36094&r=mysqlcfg
  • #36094 [NEW]: session_set_save_han... levi at alliancesoftware dot com dot au

Reply via email to