|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-01-20 00:21 UTC] sniper@php.net
[2006-01-20 03:43 UTC] levi at alliancesoftware dot com dot au
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Fri Jul 17 23:00:01 2026 UTC |
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 ...