Skip to content

Fix GH-24552: substr_compare(), ksort() and krsort() case folding uses locale - #24558

Open
lazerg wants to merge 1 commit into
php:PHP-8.4from
lazerg:fix/gh-24552-ascii-case-compare
Open

lazerg wants to merge 1 commit into
php:PHP-8.4from
lazerg:fix/gh-24552-ascii-case-compare

Conversation

@lazerg

@lazerg lazerg commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

PHP 8.2 made case-insensitive comparisons ASCII-only, but the key comparison behind ksort()/krsort() with SORT_STRING | SORT_FLAG_CASE and substr_compare() with $case_insensitive = true still called the _l variants, which go through tolower() and follow LC_CTYPE. They now use zend_binary_strcasecmp() and zend_binary_strncasecmp(), same as sort() and strncasecmp().

Fixes #24552

@LamentXU123 LamentXU123 left a comment •

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.

This looks fine. Should we credit the author of #24559 in NEWS cuz you submit identical and correct fixes in a very close time...

@LamentXU123
LamentXU123 requested a review from ndossche October 23, 2026 17:16
@sirreal

sirreal commented Oct 23, 2026 •

Copy link
Copy Markdown

I would certainly appreciate credit, thank you 🙂

Both this and my PR #24559 implement the exact fix I described in #24552. I was a bit disappointed to discover this had been submitted after I submitted the issue and before I finished submitting the PR.

Things move quickly these days 😉

@lazerg

lazerg commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

I am not against that

…uses locale

Co-authored-by: Jon Surrell <sirreal@users.noreply.github.com>
@lazerg
lazerg force-pushed the fix/gh-24552-ascii-case-compare branch from e83c07e to 55cfd71 Compare October 23, 2026 18:00
@lazerg

lazerg commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Added Jon to NEWS and as co-author on the commit, and rebased onto PHP-8.4 while I was at it. Thanks for the report and the nice write-up!

@ndossche ndossche left a comment

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.

Okay. I'm not sure this can go into 8.4 due to the behaviour change, but it's clearly a bug anyway... cc @php/release-managers-84

@NattyNarwhal

Copy link
Copy Markdown
Member

Sorry for the late response. It's annoying because the manual doesn't specify case folding for the functions, the UPGRADING notes don't cover that change for them either, and the RFC assumed they already worked like this. My feeling out of consistency and the spirit of said RFC is that this makes sense as a bugfix and that these functions need the same change. There should probably be some clarification about this in the manual or something if so.

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.

Case-insensitive substr_compare, ksort, krsort are still locale-dependent

5 participants