#36094 [Bgs->Csd]: session_set_save_handler static methods fail if in object context
| From: | levi at alliancesoftware dot com dot au | Date: | Fri, 20 Jan 2006 02:43:53 +0000 |
| Subject: | #36094 [Bgs->Csd]: session_set_save_handler static methods fail if in object context | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-92249@lists.php.net to get a copy of this message | ||
ID: 36094
User updated by: levi at alliancesoftware dot com dot au
Reported By: levi at alliancesoftware dot com dot au
-Status: Bogus
+Status: Closed
Bug Type: Scripting Engine problem
PHP Version: 5.1.2
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2006-01-20 00:21:52] 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 00:03:35] 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 ...
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=36094&edit=1