Re: [RFC] Remove \0 from default trim() character mask
| From: | Andrew F | Date: | Tue, 24 Mar 2026 19:35:05 +0000 |
| Subject: | Re: [RFC] Remove \0 from default trim() character mask | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-130438@lists.php.net to get a copy of this message | ||
On Mar 24, 2026, at 11:29, Levi Morrison <levi.morrison@datadoghq.com> wrote:
> I agree that \0 is a control byte and not whitespace, so it probably
> shouldn't be included in any of the trim functions. However, at this
> stage in PHP's lifecycle I am not sure if we should fix it.
>
> There hasn't been much discussion, so dear internals: are simply busy,
> un-opinionated, or what?
For what little it's worth, I can't imagine any practical situation where this change
would be helpful. Using trim() or its variants on binary data is likely to result in that data being
corrupted, and this will continue to be the case even if NUL is not trimmed. Changing the current
behavior is likely to break userspace code which depends on the current behavior. If, for some
reason, users find it useful to trim specific whitespace characters from binary data, they can do so
by passing a $characters mask to the function to fit their needs, rather than changing the function
for everyone.
-- Andrew F