@@ -77,21 +77,27 @@ __thread zval *os_environment = NULL;
7777__thread HashTable * worker_ini_snapshot = NULL ;
7878
7979/* Session user handler names (same structure as PS(mod_user_names)).
80- * ps_create_sid, ps_validate_sid, ps_update_timestamp added in PHP 8.3 */
80+ * In PHP 8.2, mod_user_names is a union with .name.ps_* access.
81+ * In PHP 8.3+, mod_user_names is a direct struct with .ps_* access. */
8182typedef struct {
8283 zval ps_open ;
8384 zval ps_close ;
8485 zval ps_read ;
8586 zval ps_write ;
8687 zval ps_destroy ;
8788 zval ps_gc ;
88- #if PHP_VERSION_ID >= 80300
8989 zval ps_create_sid ;
9090 zval ps_validate_sid ;
9191 zval ps_update_timestamp ;
92- #endif
9392} session_user_handlers ;
9493
94+ /* Macro to access PS(mod_user_names) handlers across PHP versions */
95+ #if PHP_VERSION_ID >= 80300
96+ #define PS_MOD_USER_NAMES (handler ) PS(mod_user_names).handler
97+ #else
98+ #define PS_MOD_USER_NAMES (handler ) PS(mod_user_names).name.handler
99+ #endif
100+
95101__thread session_user_handlers * worker_session_handlers_snapshot = NULL ;
96102
97103void frankenphp_update_local_thread_context (bool is_worker ) {
@@ -280,7 +286,7 @@ static void frankenphp_snapshot_session_handlers(void) {
280286 }
281287
282288 /* Check if user session handlers are defined */
283- if (Z_ISUNDEF (PS ( mod_user_names ). ps_open )) {
289+ if (Z_ISUNDEF (PS_MOD_USER_NAMES ( ps_open ) )) {
284290 return ; /* No user handlers to snapshot */
285291 }
286292
@@ -290,12 +296,12 @@ static void frankenphp_snapshot_session_handlers(void) {
290296 }
291297
292298 /* Copy each handler zval with incremented reference count */
293- #define SNAPSHOT_HANDLER (name ) \
294- if (!Z_ISUNDEF(PS(mod_user_names).name )) { \
295- ZVAL_COPY(&worker_session_handlers_snapshot->name, \
296- &PS(mod_user_names).name); \
299+ #define SNAPSHOT_HANDLER (handler ) \
300+ if (!Z_ISUNDEF(PS_MOD_USER_NAMES(handler) )) { \
301+ ZVAL_COPY(&worker_session_handlers_snapshot->handler, \
302+ &PS_MOD_USER_NAMES(handler)); \
297303 } else { \
298- ZVAL_UNDEF(&worker_session_handlers_snapshot->name); \
304+ ZVAL_UNDEF(&worker_session_handlers_snapshot->handler); \
299305 }
300306
301307 SNAPSHOT_HANDLER (ps_open );
@@ -304,11 +310,9 @@ static void frankenphp_snapshot_session_handlers(void) {
304310 SNAPSHOT_HANDLER (ps_write );
305311 SNAPSHOT_HANDLER (ps_destroy );
306312 SNAPSHOT_HANDLER (ps_gc );
307- #if PHP_VERSION_ID >= 80300
308313 SNAPSHOT_HANDLER (ps_create_sid );
309314 SNAPSHOT_HANDLER (ps_validate_sid );
310315 SNAPSHOT_HANDLER (ps_update_timestamp );
311- #endif
312316
313317#undef SNAPSHOT_HANDLER
314318}
@@ -320,13 +324,13 @@ static void frankenphp_restore_session_handlers(void) {
320324 }
321325
322326 /* Restore each handler zval */
323- #define RESTORE_HANDLER (name ) \
324- if (!Z_ISUNDEF(worker_session_handlers_snapshot->name )) { \
325- if (!Z_ISUNDEF(PS(mod_user_names).name )) { \
326- zval_ptr_dtor(&PS(mod_user_names).name); \
327+ #define RESTORE_HANDLER (handler ) \
328+ if (!Z_ISUNDEF(worker_session_handlers_snapshot->handler )) { \
329+ if (!Z_ISUNDEF(PS_MOD_USER_NAMES(handler) )) { \
330+ zval_ptr_dtor(&PS_MOD_USER_NAMES(handler)); \
327331 } \
328- ZVAL_COPY(&PS(mod_user_names).name, \
329- &worker_session_handlers_snapshot->name); \
332+ ZVAL_COPY(&PS_MOD_USER_NAMES(handler), \
333+ &worker_session_handlers_snapshot->handler); \
330334 }
331335
332336 RESTORE_HANDLER (ps_open );
@@ -335,11 +339,9 @@ static void frankenphp_restore_session_handlers(void) {
335339 RESTORE_HANDLER (ps_write );
336340 RESTORE_HANDLER (ps_destroy );
337341 RESTORE_HANDLER (ps_gc );
338- #if PHP_VERSION_ID >= 80300
339342 RESTORE_HANDLER (ps_create_sid );
340343 RESTORE_HANDLER (ps_validate_sid );
341344 RESTORE_HANDLER (ps_update_timestamp );
342- #endif
343345
344346#undef RESTORE_HANDLER
345347}
@@ -355,9 +357,9 @@ static void frankenphp_cleanup_worker_state(void) {
355357
356358 /* Free session handlers snapshot */
357359 if (worker_session_handlers_snapshot != NULL ) {
358- #define FREE_HANDLER (name ) \
359- if (!Z_ISUNDEF(worker_session_handlers_snapshot->name )) { \
360- zval_ptr_dtor(&worker_session_handlers_snapshot->name); \
360+ #define FREE_HANDLER (handler ) \
361+ if (!Z_ISUNDEF(worker_session_handlers_snapshot->handler )) { \
362+ zval_ptr_dtor(&worker_session_handlers_snapshot->handler); \
361363 }
362364
363365 FREE_HANDLER (ps_open );
@@ -366,11 +368,9 @@ static void frankenphp_cleanup_worker_state(void) {
366368 FREE_HANDLER (ps_write );
367369 FREE_HANDLER (ps_destroy );
368370 FREE_HANDLER (ps_gc );
369- #if PHP_VERSION_ID >= 80300
370371 FREE_HANDLER (ps_create_sid );
371372 FREE_HANDLER (ps_validate_sid );
372373 FREE_HANDLER (ps_update_timestamp );
373- #endif
374374
375375#undef FREE_HANDLER
376376
0 commit comments