# User defined session handlers

- Thread: https://externals.io/message/12916
- Original archive: https://news-web.php.net/php.internals/12916
- Started by Sara Golemon on 2004-09-20T17:34:59+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #12916 — Sara Golemon — 2004-09-20T17:34:59+00:00

URL: https://externals.io/message/12916#12916

The sessions extension allows customizable modules for session storage via 
callbacks.  Module callbacks expect SUCCESS or FAILURE as return values as 
illustrated in the use of session opener below:

if (PS(mod)->s_open(&PS(mod_data), PS(save_path), PS(session_name) 
TSRMLS_CC) == FAILURE) {

However, in the user defined session module (ext/session/mod_user.c), each 
callback (after calling the user defined function) terminates with a call to 
the "FINISH" macro which, if no retval was given returns SUCCESS or FAILURE 
depending on whether or not the user callback worked (fine and dandy).

#define FINISH                              \
    if (retval) {                           \
        convert_to_long(retval);            \
        ret = Z_LVAL_P(retval);         \
        zval_ptr_dtor(&retval);             \
    }                                       \
    return ret


However, if a return value is given, then the lval of that return value is 
used instead. Now, say true was given to indicate that the callback 
succeeded, true's lval is 1.  Remembering that:

#define SUCCESS 0
#define FAILURE 1

We see that the logic is flipped upside down.  Here false means success and 
true means failure.

Question:  Should the macro be fixed to match documentation?  Or should 
documentation be fixed to match behavior?

Option C: Am I out of my mind and missed something obvious which means that 
all this actually works.

-Sara
