|
Posted by Jerry Stuckle on 04/17/06 15:36
_Mario.lat wrote:
> Hallo,
> I have a little question:
> In the function session_set_save_handler I can pass the name of function
> which deal with session.
> In Xoops code I see the use of this function like that:
>
> session_set_save_handler(array(&$sess_handler, 'open'),
> array(&$sess_handler, 'close'), array(&$sess_handler, 'read'),
> array(&$sess_handler, 'write'), array(&$sess_handler, 'destroy'),
> array(&$sess_handler, 'gc'));
>
> How does it works?
> why it use "array(&$sess_handler, 'open')" and not "$sess_handler->open"
> ? How "array(&$sess_handler, 'open')" works?
> Thank you in advance for the time you'll spend for me. Mario.
>
>
<code snipped>
You can't just pass $sess)handler->open to the function because it is a member
(method) of a class. And to call a non-static method, you need an object of
that class.
$sess_handler->open is just a pointer to the function; it doesn't have an object
associated to it. So if you were to call it, there would be no object for the
method to use.
OTOH, when you pass array(&$sess_handler, 'open'), you are passing an object
($sess_handler) by reference. You are also passing the name of a method
('open') as a string. So session_set_save_handler has all it needs to use the
class - an object and a method. And it has this information for each of the six
methods it needs.
Hope this is clear.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|