开发者

PHP error: Indirect modification of overloaded property

I am trying to build my own session handler for (currently) database storage. When calling it as a normal OOP as shown below in the first example, everything works as intended. Data is stored to the database without any issues.

However when putting it together with the session_set_save_handler function to be able to use the $_SESSION global variable, PHP goes bananas like never before and start outputting multiple Notice: Indirect modification of overloaded property errors.

What am I doing wrong to cause these horrific errors?


Working code example:

class session extends sessionBase {

    private $db;

    function __construct() {
        parent::__construct();
        $this->db = database::get()->connection();
    }

    function write() {
        // Query to database
    }
}

$session = new session;
session->write(); // Writes to database perfectly

Non-working code example:

class session extends sessionBase {

    private $db;

    function __construct() {
        parent::__construct();
        $this->db = database::get()->connection();
    }

    function write() {
        // Query to database
    }
}

$sessions = New session();

session_set_save_handler(
array($sessions,"open"),
array($sessions,"close"),
array($sessions,"read"),
array($sessions,"write"),
array($sessions,"destroy"),
array($sessions,"gc")
);

session_start(); // This is bananas开发者_如何学JAVA! B-A-N-A-N-A-S! 


The error "Indirect modification of overloaded property" is well known in the context of changing arrays returned by __get.

I could thus imagine that read has to return by reference:

public function &read(...) {
    ...
}

But following from the fact that this is mentioned nowhere on the whole internet, I assume that the fault lies in someplace different. Probably in some of your "unrelated" code.


Go to www.anindya.com download *php_curl-5.4.3-VC9-x64.zip* under "Fixed curl extensions:" and replace the php_curl.dll in ext folder.

Found related issue on: http://forum.wampserver.com/read.php?2,85716,printview,page=1

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜