User defined session handlers

php.internals

Sara Golemon

21 years ago
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