Re: [RFC] Prepared Literal String Matching and Replacement

From: Date: Mon, 23 Nov 2026 20:46:49 +0000
Subject: Re: [RFC] Prepared Literal String Matching and Replacement
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-133209@lists.php.net to get a copy of this message
Hi On 2026-11-23 20:36, Artem Ukrainskiy wrote:
I plan to open the vote on 11 January 2027, after the holidays, for two weeks. If you have concerns, now is a good time to raise them.
Thank you for your RFC and for the explicit note about pushing the vote to after the holidays at the very earliest. The last few weeks have been busy with two important security releases and of course the PHP 8.6 stable release. I don't currently have the time to read the entire RFC in depth, but I already wanted to raise a point about something that is likely the most controversial in the RFC and that in my opinion needs strong justification, but currently has none: The introduction of the Str\ namespace. This would be the first namespaced functionality for the scalar types and I think we should not take that step lightly without having an overarching plan for the hierarchy. As I had noted in my blog post on the PHP Foundation’s blog (https://thephp.foundation/blog/2026/11/03/stdlib-investment/):
Since namespaces were introduced after a large part of PHP’s existing standard library was built, they provide a rare opportunity for a second attempt. The replacement API can sit in an as yet empty namespace without touching the behavior of the existing API that PHP developers have come to rely on.
As an example, I do not find it obvious at all that the namespace should be called Str rather than string (or String), matching the name of the type. The unqualified names of the three classes are also awfully generic and potentially preclude future extensions: There clearly are more possible ways of “matching strings” than a scan for (sub)string literals. The new stdlib APIs that we've introduced lately clearly specify the “algorithm” or standard they implement in the name (e.g. Random\Engine\Xoshiro256StarStar or Uri\Rfc3986\Uri). Now Aho-Corasick is clearly not something that folks will intuitively find in the documentation, and there might be an opportunity to improve the implementation if a better algorithm is developed. So using the algorithm name here is probably not a good idea and we should find some better term for the concept. To throw a specific suggestion in the ring: How about calling this StrSet or StrSetMatcher in the global namespace? The “Set” part seems to appropriately define what this is about. No good idea for the “Replacer” class. Maybe StrSetReplacer just works. Or maybe we can merge the classes somehow. By putting it in the global namespace we leave the future scope for a larger redesign of the string functions. The introduction of the namespace should probably come with a “full set” of well-designed string functions including clearly spelled out API design guidelines (e.g. parameter order) that can be referenced for future additions. Best regards Tim Düsterhus

« previous php.internals (#133209) next »