Skip to content

session: fix create_sid()/validateId() check depending on interface order - #23329

Open
lazerg wants to merge 3 commits into
php:masterfrom
lazerg:fix/gh-23328-session-iface-order
Open

session: fix create_sid()/validateId() check depending on interface order#23329
lazerg wants to merge 3 commits into
php:masterfrom
lazerg:fix/gh-23328-session-iface-order

Conversation

@lazerg

@lazerg lazerg commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

session_handler_interface_gets_implemented() runs while SessionHandlerInterface is being attached to the class, so class->function_table only holds what the class itself declares. Interfaces listed after it have not contributed their abstract methods yet, which is why the warning fires or not depending on the order of the implements list.

The check now also looks for the two methods in the function tables of the interfaces the class implements, which zend_do_implement_interfaces() fills in before it starts calling the handlers. Staying on method presence rather than interface identity keeps it consistent with session_set_save_handler(), which accepts the methods whether or not the interface is implemented.

Closes #23328

@lazerg

lazerg commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

The Alpine ASAN failure is ext/mysqli/tests/protocol_stmt_row_fetch_data.phpt, which fails on master too. It is not caused by this change.

Comment thread ext/session/session.c
Comment on lines +2942 to +2946
for (uint32_t i = 0; i < ce->num_interfaces; i++) {
if (zend_hash_str_exists(&ce->interfaces[i]->function_table, name, name_len)) {
return true;
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather we iterate on ce->interfaces[i] and check that the CE is SessionIdInterface or SessionUpdateTimestampHandlerInterface rather than name checking.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in a783cff. It iterates ce->interfaces[i] and uses instanceof_function() per entry, so an interface that extends SessionIdInterface or SessionUpdateTimestampHandlerInterface is still recognised before it has been flattened into the list.

One case this drops, which the name check covered: a class that gets the methods from an unrelated interface. implements OwnMethods, SessionHandlerInterface stays quiet, implements SessionHandlerInterface, OwnMethods now warns again. session_set_save_handler() accepts the methods there regardless of the interface, so the two rules differ. Tell me if you want that case back and I will restore the method lookup.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering the objective is to move the methods from those 2 interfaces to the "base" interface having another interface declare such a method is not something we should be supporting.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move this test into the user_session_submodule subdirectory

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to ext/session/tests/user_session_module/gh23328.phpt in a783cff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SessionHandlerInterface create_sid()/validateId() warning depends on the order interfaces are listed in

2 participants