Skip to content

ext/session: only return false when could not encode session at all#21181

Merged
Girgias merged 2 commits intophp:masterfrom
Girgias:2026-02-session-if-encode-null-then-failure
Feb 16, 2026
Merged

ext/session: only return false when could not encode session at all#21181
Girgias merged 2 commits intophp:masterfrom
Girgias:2026-02-session-if-encode-null-then-failure

Conversation

@Girgias
Copy link
Member

@Girgias Girgias commented Feb 9, 2026

This also fixes bug 71162.

I'm targeting master with this change as it is long-standing behaviour, but I don't really understand why an "empty session" would fail to encode. Similarly, with a "partial" encoding of it when discarding numeric keys.

The biggest impact is that session_encode() now only returns false in very limited cases and for empty sessions returns an empty string, which is how it was encoded anyway when actually performing session writes.

// TODO warn that ID cannot be verified? else { }
}
/* Read is required to make new session data at this point. */
zend_string *data;
Copy link
Member

Choose a reason for hiding this comment

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

I think it should be initialised to NULL wdyt ?

Copy link
Member

Choose a reason for hiding this comment

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

Hm, it wasn't previously though, so is that a bug then do you think?

Copy link
Member

Choose a reason for hiding this comment

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

not sure all callbacks guarantee initialisation, this is all I m saying but I do not session that well :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it was always initialized prior to the rename because it would either be NULL or hold a dangling pointer. So not sure there is a bug, but I'll initialize it to NULL just because it's the most sensible.

// TODO warn that ID cannot be verified? else { }
}
/* Read is required to make new session data at this point. */
zend_string *data;
Copy link
Member

Choose a reason for hiding this comment

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

Hm, it wasn't previously though, so is that a bug then do you think?

@Girgias Girgias force-pushed the 2026-02-session-if-encode-null-then-failure branch from 51cc14b to 37698f3 Compare February 10, 2026 12:52
@Girgias Girgias marked this pull request as ready for review February 10, 2026 14:00
Copy link
Member

@ndossche ndossche left a comment

Choose a reason for hiding this comment

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

Looks logical, not sure how big the BC impact is, I'll leave that assessment to you. Although I presume that the edge case where this happens doesn't occur much in practice.

@Girgias Girgias merged commit 86b4921 into php:master Feb 16, 2026
10 checks passed
@Girgias Girgias deleted the 2026-02-session-if-encode-null-then-failure branch February 16, 2026 11:44
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.

3 participants