|
Posted by Sjoerd on 04/17/06 14:42
> session_set_save_handler(array(&$sess_handler, 'open'),
The first parameter would be the object on which to invoke a method.
The second parameter would be the name of the method ('open').
In session_set_save_handler, when an open occurs, it calls
$sess_handler->$name_of_method. The method $sess_handler->open is
actually a callback function.
Without the use of objects, a callback function would be a normal
function. You would pass the name of the function as a parameter:
<?php
function foo($functionname) {
echo $functionname('hello');
}
foo('strtoupper');
?>
As you can see, 'strtoupper' is passed as a parameter and then used as
a function.
This won't work for objects:
<?php
foo('$obj->open');
foo('Object::Open');
?>
The first does not work because the variable $obj is not passed
correctly. The second way also does not work, but I can not think of a
good reason why it doesn't.
The right way, design-wise, to set a handler is to pass an object which
implements an interface. The interface specifies which methods an
object has to have, such as open, close, etc. You then pass an object
which implements this interface and the methods within this object can
be called.
[Back to original message]
|