views:

549

answers:

2

I am writing a custom session handler in PHP and trying to make the methods defined in session_set_save_handler private.

session_set_save_handler(
    array('Session','open'),
    array('Session','close'),
    array('Session','read'),
    array('Session','write'),
    array('Session','destroy'),
    array('Session','gc')
);

For example I can set the open function to be private without any errors, but when I make the write method private it barks at me.

Fatal error: Call to private method Session::write() from context '' in Unknown on line 0

I was just wondering if this was a bug or there is a way around this. Barring that I can certainly just make it public, but I'd rather not. There was a post from last year on php.net eluding to a similar thing, but just want to know if anyone had any ideas. Does it really matter? I am using PHP 5.2.0 on my development box, but could certainly upgrade.

+4  A: 

They have to be public. Your class is instantiated and called in exactly the manner you would in your own code.

So, unless you can figure out how to publically call a private method on ANY class, then no =P

Peter Bailey
Gotcha. Makes sense.
Chris Kloberdanz
A: 

Pass an instantiated object as the first param of your callback array.

$session = new Session(); session_set_save_handler( array($session,'open'), array($session,'close'), array($session,'read'), array($session,'write'), array($session,'destroy'), array($session,'gc') );

fentie
Then you’re just using object methods instead of class methods. But those must be public as well.
Gumbo