[RFC] Remove \0 from default trim() character mask
| From: | LamentXU | Date: | Sun, 15 Mar 2026 06:20:41 +0000 |
| Subject: | [RFC] Remove \0 from default trim() character mask | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-130318@lists.php.net to get a copy of this message | ||
Dear all,
I am sending this to introduce my new RFC: https://wiki.php.net/RFC/dont_trim_NUL
Quick summary:
Currently, PHP's trim functions strip the NUL byte (\0) by default, treating it alongside
spaces, tabs, and newlines. This creates a highly surprising edge case.
Because \0 is semantically a control character or a vital part of a binary payload rather than a
typographical whitespace character, casually using trim() to clean up trailing newlines can silently
corrupt binary streams or cryptographic hashes by stripping legitimate NUL bytes. Whitespace
characters are intended for typographical spacing and formatting (e.g., spaces, newlines, tabs).
Also, almost every mainstream programming languages except PHP doesn't trim NUL characters
(python, go, rust, js, even 'is_space' function in glibc...) It sounds reasonable to
expect the same here.
This RFC proposes removing \0 (ASCII 0) from the default character mask. I recognize this introduces
a backward compatibility break, and therefore I would love to hear your thoughts, feedback, and any
concerns regarding the BC impact before moving forward.
Cheers,
Weilin Du