Hi internals,
I'd like to open discussion on this RFC: https://wiki.php.net/rfc/prepared_literal_string_matching
It proposes Str\Matcher and Str\Replacer for prepared literal substring search and replacement. Matcher provides presence checks, unique matched keywords, occurrence counts, and enumeration of all overlapping matches with byte offsets, using Str\MatchResult objects. Replacer performs non-overlapping replacements, choosing the earliest start and then the longest key, without rescanning inserted text.
Both classes prepare an immutable dictionary during construction. Matching is byte-oriented, binary-safe, and case-sensitive. Objects can be reused within a request or in long-running applications.
I've implemented the API and published reproducible benchmarks covering both prepared calls and one-shot use, including construction and destruction.
Preparation can pay off even for a single call on some inputs. On others, existing PHP functions or PCRE remain faster, even than a prepared object.
I propose including these classes in ext/standard in the Str namespace. The current implementation is in ext/strmatch. I'd welcome feedback on the API, integration, error types, and whether Matcher and Replacer should be considered together or separately.
Implementation:
https://github.com/php/php-src/pull/25122
Benchmarks, methodology and raw data:
https://github.com/ArtUkrainskiy/php-src-bench/tree/main/reports/multi-pattern-search
Best regards,
Artem Ukrainskiy
Quoted text · 13 lines
Hi internals,
I'd like to open discussion on this RFC: https://wiki.php.net/rfc/prepared_literal_string_matching
It proposes Str\Matcher and Str\Replacer for prepared literal substring search and replacement. Matcher provides presence checks, unique matched keywords, occurrence counts, and enumeration of all overlapping matches with byte offsets, using Str\MatchResult objects. Replacer performs non-overlapping replacements, choosing the earliest start and then the longest key, without rescanning inserted text.
Both classes prepare an immutable dictionary during construction. Matching is byte-oriented, binary-safe, and case-sensitive. Objects can be reused within a request or in long-running applications.
I've implemented the API and published reproducible benchmarks covering both prepared calls and one-shot use, including construction and destruction. Preparation can pay off even for a single call on some inputs. On others, existing PHP functions or PCRE remain faster, even than a prepared object.
I propose including these classes in ext/standard in the Str namespace. The current implementation is in ext/strmatch. I'd welcome feedback on the API, integration, error types, and whether Matcher and Replacer should be considered together or separately.
Implementation:
https://github.com/php/php-src/pull/25122Benchmarks, methodology and raw data:
https://github.com/ArtUkrainskiy/php-src-bench/tree/main/reports/multi-pattern-search--
Best regards,
Artem Ukrainskiy
This looks interesting, and I'm not opposed to it. It somewhat parallels the recently discussed Pcre class.
My main question is that this feels very niche. Based on the benchmarks, if I'm reading them correctly, it sounds like 90% of uses would be better served with the existing APIs. Does this make sense for stdlib then? It would be helpful to include more practical examples of where I'd want to use this instead of str_contains(), rather than just a table of byte counts. The "Where the API can help" section isn't sufficient as-is.
For example... would this pay off in a long-running process like FrankenPHP or Swoole, if the object is saved between requests?
Other issues:
-
Matcher::matchAll() returns a list, but each of the items in it contains, I believe, a unique value. Could it then return a keyed array for easier lookup? (The example suggests I may be wrong, but if so, please spell this out explicitly.)
-
The inout $count argument to Replacer::replace(): Eew. Please explore a better way of handling that. inout params in a language like PHP are the absolute last resort.
-
I'm not clear if it says explicitly anywhere if there's behavioral differences from the existing functions. If so it wasn't clear. Would swapping Replacer in for
strtr()require any subtle logic changes, or is it a drop-in syntax change? That should be made explicit. -
"Reinitializing an already prepared object throws an Error, even if its dictionary is empty." - How would one reinitialize it? Do you mean calling the constructor explicitly, which PHP allows even though it's never ever safe to do anyway? :-) If so, please clarify that's what you mean.
-
"two distinct objects compare unequal with ==, even if their dictionaries are identical. " - I disagree with this. The whole point of == on objects is to ask "are these equivalent," and two Matchers with the same dictionary are equivalent. Thus they should be ==.
-
The RFC notes that these routines are byte-based only, which is fine, as that's what most of PHP is. However, is there a use for a Unicode/Grapheme equivalent? Even if future scope, it's worth mentioning.
-
In "Design choices," you list how existing implementations in other languages differ. Please also explain why you've chosen to not follow the same semantics as one of the existing tools, as that means someone moving from those languages to PHP is going to be easily confused by the edge cases.
-
In "Where existing tools are preferable", there's a broken link in the 2nd paragraph.
-
These are closely related enough that I think a single vote is fine. There's no need to separate them.
--Larry Garfield
Hi Larry,
Thanks for the review. I've updated the RFC to v0.4 and redone the measurements. The algorithm itself got further optimizations, and I revised the benchmark methodology, so the results are more honest and closer to real product scenarios. The old numbers ran one text over and over. The CPU learned it, and the new class looked 3-4 times faster than it is. Calls now go through a pool of different texts. The code has moved to ext/standard.
I've also substantially rewritten the RFC and the benchmark report. I removed ambiguous wording and repetition, and put the product scenarios first.
My main question is that this feels very niche. Based on the benchmarks, if I'm reading them correctly, it sounds like 90% of uses would be better served with the existing APIs. Does this make sense for stdlib then?
That share came from the measurement matrix I picked, not from real applications, so I don't quote it anymore. Instead the RFC now has three scenarios on real data: comment moderation, bot detection by User-Agent and auto-linking PHP manual pages. With a reused object the new class is 8-123 times faster than the fastest existing method. One call on a short text is slower, and the RFC says so directly. On long texts one call pays off too: auto-linking 4-16 KiB manual pages with 128-512 names is 2.9-3.6 times faster.
For example... would this pay off in a long-running process like FrankenPHP or Swoole, if the object is saved between requests?
Yes, that's the main use case. The object is built when the worker starts and lives across requests, so the build is paid once. The Summary table estimates how many calls repay the build.
- Matcher::matchAll() returns a list, but each of the items in it contains, I believe, a unique value. Could it then return a keyed array for easier lookup?
The items aren't unique. In 'aaa' the key 'a' occurs three times and 'aa' twice, and different keys can start at the same offset. An array keyed by keyword or by offset would lose results. getMatchedKeywords() returns the unique keys. The RFC now spells this out with that example.
- The inout $count argument to Replacer::replace(): Eew. Please explore a better way of handling that.
Removed. replace() returns only the string, and a replacement count moved to Future Scope. Honestly, I don't think it's needed.
Would swapping Replacer in for
strtr()require any subtle logic changes, or is it a drop-in syntax change?
For a dictionary of non-empty keys and string values the result is the same. The only differences are in checking the dictionary. An empty key throws ValueError, while strtr() skips it with a warning. A non-string value throws TypeError, while strtr() converts it. The object keeps a snapshot of the dictionary. The RFC lists this in the Replacer section.
How would one reinitialize it? Do you mean calling the constructor explicitly, which PHP allows even though it's never ever safe to do anyway? :-)
Yes, I meant calling $object->__construct(...) again. The error table now says exactly that.
The whole point of == on objects is to ask "are these equivalent," and two Matchers with the same dictionary are equivalent. Thus they should be ==.
Agreed, done. == on Matcher compares the sets of keys, on Replacer the key => value pairs, ignoring order. === still compares identity.
However, is there a use for a Unicode/Grapheme equivalent? Even if future scope, it's worth mentioning.
Exact UTF-8 search already works, since bytes are compared. A grapheme API would be useful, for example for highlighting, but it's a separate contract: grapheme boundaries, offset units, normalization, case. I'm not including it in this RFC.
Please also explain why you've chosen to not follow the same semantics as one of the existing tools
Replacement follows strtr(): existing PHP dictionaries give the same result, and that matters more to me than compatibility with another language. Rust's aho-corasick has both modes, and LeftmostLongest picks matches the same way as Replacer. Go resolves conflicts by argument order: with the pairs a => Y and aa => X, the string aa becomes YY in Go and X in Replacer and strtr(). This is in "Design choices". Matching modes might be a future extension of the API.
- In "Where existing tools are preferable", there's a broken link in the 2nd paragraph.
That was the {{...}} example, which DokuWiki read as media markup. The item referred to the old measurements and isn't in v0.4.
These are closely related enough that I think a single vote is fine.
Agreed.
On Fri, Nov 6, 2026 at 6:54 PM Larry Garfield larry@garfieldtech.com wrote:
Quoted text · 38 lines
Hi internals,
I'd like to open discussion on this RFC: https://wiki.php.net/rfc/prepared_literal_string_matching
It proposes Str\Matcher and Str\Replacer for prepared literal substring search and replacement. Matcher provides presence checks, unique matched keywords, occurrence counts, and enumeration of all overlapping matches with byte offsets, using Str\MatchResult objects. Replacer performs non-overlapping replacements, choosing the earliest start and then the longest key, without rescanning inserted text.
Both classes prepare an immutable dictionary during construction. Matching is byte-oriented, binary-safe, and case-sensitive. Objects can be
reused within a request or in long-running applications.I've implemented the API and published reproducible benchmarks covering both prepared calls and one-shot use, including construction and destruction.
Preparation can pay off even for a single call on some inputs. On others, existing PHP functions or PCRE remain faster, even than a prepared object.I propose including these classes in ext/standard in the Str namespace. The current implementation is in ext/strmatch. I'd welcome feedback on the API, integration, error types, and whether Matcher and Replacer should be considered together or separately.
Implementation:
https://github.com/php/php-src/pull/25122Benchmarks, methodology and raw data:
https://github.com/ArtUkrainskiy/php-src-bench/tree/main/reports/multi-pattern-search
--
Best regards,
Artem UkrainskiyThis looks interesting, and I'm not opposed to it. It somewhat parallels the recently discussed Pcre class.
My main question is that this feels very niche. Based on the benchmarks, if I'm reading them correctly, it sounds like 90% of uses would be better served with the existing APIs. Does this make sense for stdlib then? It would be helpful to include more practical examples of where I'd want to use this instead of
str_contains(), rather than just a table of byte counts. The "Where the API can help" section isn't sufficient as-is.For example... would this pay off in a long-running process like FrankenPHP or Swoole, if the object is saved between requests?
Other issues:
Matcher::matchAll() returns a list, but each of the items in it contains, I believe, a unique value. Could it then return a keyed array for easier lookup? (The example suggests I may be wrong, but if so, please spell this out explicitly.)
The inout $count argument to Replacer::replace(): Eew. Please explore a better way of handling that. inout params in a language like PHP are the absolute last resort.
I'm not clear if it says explicitly anywhere if there's behavioral differences from the existing functions. If so it wasn't clear. Would swapping Replacer in for
strtr()require any subtle logic changes, or is it a drop-in syntax change? That should be made explicit."Reinitializing an already prepared object throws an Error, even if its dictionary is empty." - How would one reinitialize it? Do you mean calling the constructor explicitly, which PHP allows even though it's never ever safe to do anyway? :-) If so, please clarify that's what you mean.
"two distinct objects compare unequal with ==, even if their dictionaries are identical. " - I disagree with this. The whole point of == on objects is to ask "are these equivalent," and two Matchers with the same dictionary are equivalent. Thus they should be ==.
The RFC notes that these routines are byte-based only, which is fine, as that's what most of PHP is. However, is there a use for a Unicode/Grapheme equivalent? Even if future scope, it's worth mentioning.
In "Design choices," you list how existing implementations in other languages differ. Please also explain why you've chosen to not follow the same semantics as one of the existing tools, as that means someone moving from those languages to PHP is going to be easily confused by the edge cases.
In "Where existing tools are preferable", there's a broken link in the 2nd paragraph.
These are closely related enough that I think a single vote is fine. There's no need to separate them.
--Larry Garfield
--
Best regards,
Artem Ukrainskiy
Hi internals,
I've updated the RFC to v0.5 and closed the open issues:
- Target version is PHP 8.7.
- There's one vote on the whole API, as Larry suggested. Str\MatchResult only makes sense with Str\Matcher, and both classes are built on the same Aho-Corasick automaton.
- The names stay as they are. GitHub code search finds no other classes named Str\Matcher, Str\Replacer or Str\MatchResult.
- The voting widget is added. The API and the implementation haven't changed since v0.4.
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.
RFC: https://wiki.php.net/rfc/prepared_literal_string_matching Implementation: https://github.com/php/php-src/pull/25122
On Fri, Nov 13, 2026 at 4:54 AM Artem Ukrainskiy art.ukrainskiy@gmail.com wrote:
Quoted text · 68 lines
Hi Larry,
Thanks for the review. I've updated the RFC to v0.4 and redone the measurements. The algorithm itself got further optimizations, and I revised the benchmark methodology, so the results are more honest and closer to real product scenarios. The old numbers ran one text over and over. The CPU learned it, and the new class looked 3-4 times faster than it is. Calls now go through a pool of different texts. The code has moved to ext/standard.
I've also substantially rewritten the RFC and the benchmark report. I removed ambiguous wording and repetition, and put the product scenarios first.
My main question is that this feels very niche. Based on the benchmarks, if I'm reading them correctly, it sounds like 90% of uses would be better served with the existing APIs. Does this make sense for stdlib then?
That share came from the measurement matrix I picked, not from real applications, so I don't quote it anymore. Instead the RFC now has three scenarios on real data: comment moderation, bot detection by User-Agent and auto-linking PHP manual pages. With a reused object the new class is 8-123 times faster than the fastest existing method. One call on a short text is slower, and the RFC says so directly. On long texts one call pays off too: auto-linking 4-16 KiB manual pages with 128-512 names is 2.9-3.6 times faster.
For example... would this pay off in a long-running process like FrankenPHP or Swoole, if the object is saved between requests?
Yes, that's the main use case. The object is built when the worker starts and lives across requests, so the build is paid once. The Summary table estimates how many calls repay the build.
- Matcher::matchAll() returns a list, but each of the items in it contains, I believe, a unique value. Could it then return a keyed array for easier lookup?
The items aren't unique. In 'aaa' the key 'a' occurs three times and 'aa' twice, and different keys can start at the same offset. An array keyed by keyword or by offset would lose results. getMatchedKeywords() returns the unique keys. The RFC now spells this out with that example.
- The inout $count argument to Replacer::replace(): Eew. Please explore a better way of handling that.
Removed. replace() returns only the string, and a replacement count moved to Future Scope. Honestly, I don't think it's needed.
Would swapping Replacer in for
strtr()require any subtle logic changes, or is it a drop-in syntax change?For a dictionary of non-empty keys and string values the result is the same. The only differences are in checking the dictionary. An empty key throws ValueError, while
strtr()skips it with a warning. A non-string value throws TypeError, whilestrtr()converts it. The object keeps a snapshot of the dictionary. The RFC lists this in the Replacer section.How would one reinitialize it? Do you mean calling the constructor explicitly, which PHP allows even though it's never ever safe to do anyway? :-)
Yes, I meant calling $object->__construct(...) again. The error table now says exactly that.
The whole point of == on objects is to ask "are these equivalent," and two Matchers with the same dictionary are equivalent. Thus they should be ==.
Agreed, done. == on Matcher compares the sets of keys, on Replacer the key => value pairs, ignoring order. === still compares identity.
However, is there a use for a Unicode/Grapheme equivalent? Even if future scope, it's worth mentioning.
Exact UTF-8 search already works, since bytes are compared. A grapheme API would be useful, for example for highlighting, but it's a separate contract: grapheme boundaries, offset units, normalization, case. I'm not including it in this RFC.
Please also explain why you've chosen to not follow the same semantics as one of the existing tools
Replacement follows
strtr(): existing PHP dictionaries give the same result, and that matters more to me than compatibility with another language. Rust's aho-corasick has both modes, and LeftmostLongest picks matches the same way as Replacer. Go resolves conflicts by argument order: with the pairs a => Y and aa => X, the string aa becomes YY in Go and X in Replacer andstrtr(). This is in "Design choices". Matching modes might be a future extension of the API.
- In "Where existing tools are preferable", there's a broken link in the 2nd paragraph.
That was the {{...}} example, which DokuWiki read as media markup. The item referred to the old measurements and isn't in v0.4.
These are closely related enough that I think a single vote is fine.
Agreed.
On Fri, Nov 6, 2026 at 6:54 PM Larry Garfield larry@garfieldtech.com wrote:
Hi internals,
I'd like to open discussion on this RFC: https://wiki.php.net/rfc/prepared_literal_string_matching
It proposes Str\Matcher and Str\Replacer for prepared literal substring search and replacement. Matcher provides presence checks, unique matched keywords, occurrence counts, and enumeration of all overlapping matches with byte offsets, using Str\MatchResult objects. Replacer performs non-overlapping replacements, choosing the earliest start and then the longest key, without rescanning inserted text.
Both classes prepare an immutable dictionary during construction. Matching is byte-oriented, binary-safe, and case-sensitive. Objects can be
reused within a request or in long-running applications.I've implemented the API and published reproducible benchmarks covering both prepared calls and one-shot use, including construction and destruction.
Preparation can pay off even for a single call on some inputs. On others,
existing PHP functions or PCRE remain faster, even than a prepared object.I propose including these classes in ext/standard in the Str namespace. The current implementation is in ext/strmatch. I'd welcome feedback on the API, integration, error types, and whether Matcher and Replacer should be considered together or separately.
Implementation:
https://github.com/php/php-src/pull/25122Benchmarks, methodology and raw data:
https://github.com/ArtUkrainskiy/php-src-bench/tree/main/reports/multi-pattern-search
--
Best regards,
Artem UkrainskiyThis looks interesting, and I'm not opposed to it. It somewhat parallels the recently discussed Pcre class.
My main question is that this feels very niche. Based on the benchmarks, if I'm reading them correctly, it sounds like 90% of uses would be better served with the existing APIs. Does this make sense for stdlib then? It would be helpful to include more practical examples of where I'd want to use this instead of
str_contains(), rather than just a table of byte counts. The "Where the API can help" section isn't sufficient as-is.For example... would this pay off in a long-running process like FrankenPHP or Swoole, if the object is saved between requests?
Other issues:
Matcher::matchAll() returns a list, but each of the items in it contains, I believe, a unique value. Could it then return a keyed array for easier lookup? (The example suggests I may be wrong, but if so, please spell this out explicitly.)
The inout $count argument to Replacer::replace(): Eew. Please explore a better way of handling that. inout params in a language like PHP are the absolute last resort.
I'm not clear if it says explicitly anywhere if there's behavioral differences from the existing functions. If so it wasn't clear. Would swapping Replacer in for
strtr()require any subtle logic changes, or is it a drop-in syntax change? That should be made explicit."Reinitializing an already prepared object throws an Error, even if its dictionary is empty." - How would one reinitialize it? Do you mean calling the constructor explicitly, which PHP allows even though it's never ever safe to do anyway? :-) If so, please clarify that's what you mean.
"two distinct objects compare unequal with ==, even if their dictionaries are identical. " - I disagree with this. The whole point of == on objects is to ask "are these equivalent," and two Matchers with the same dictionary are equivalent. Thus they should be ==.
The RFC notes that these routines are byte-based only, which is fine, as that's what most of PHP is. However, is there a use for a Unicode/Grapheme equivalent? Even if future scope, it's worth mentioning.
In "Design choices," you list how existing implementations in other languages differ. Please also explain why you've chosen to not follow the same semantics as one of the existing tools, as that means someone moving from those languages to PHP is going to be easily confused by the edge cases.
In "Where existing tools are preferable", there's a broken link in the 2nd paragraph.
These are closely related enough that I think a single vote is fine. There's no need to separate them.
--Larry Garfield
--
Best regards,
Artem Ukrainskiy
--
Best regards,
Artem Ukrainskiy
Hi
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
As an example, I do not find it obvious at all that the namespace should be called
Strrather thanstring(or String), matching the name of the type.
Agreed on this bit. We're still getting rid of legacy names like "integer" and "double"; we should avoid introducing new naming surprises.
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\Xoshiro256StarStarorUri\Rfc3986\Uri).
I have to disagree with this bit, though. The fundamental functionality which these methods provide is string matching and replacement. The use of Aho-Corasick to implement this is an implementation detail which users should not need to be concerned with, and which PHP should be able to change if a better implementation is found. (By way of example: the standard sorting function is called sort(), not quicksort().)
On a more general note, this RFC is conflating two distinct improvements to PHP: a better interface for match-and-replace operations, and a faster implementation of those operations. Tying those two changes together feels less than ideal - are there ways that we could e.g. make existing functions like str_replace() use Aho-Corasick in situations where it would be helpful, or to make Matcher/Replacer abstain from using it in cases where a simple search would be faster?
-- Andrew F
Hi
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\Xoshiro256StarStarorUri\Rfc3986\Uri).I have to disagree with this bit, though. The fundamental functionality which these methods provide is string matching and replacement. The use of Aho-Corasick to implement this is an implementation detail which users should not need to be concerned with, and which PHP should be able to change if a better implementation is found. (By way of example: the standard sorting function is called
sort(), not quicksort().)
Yes. I acknowledge that myself in the literal sentence that follows after the part you quoted. My point about “this is a specific type of matching that is being performed by those classes” stands though, and I believe the classes should be renamed.
Best regards
Tim Düsterhus
Hi Tim, Andrew,
Tim, I agree on the namespace. A namespace for strings should be designed as a whole. String functions are spread over ext/standard, mbstring, intl and PCRE today, and that's work for a separate effort. One class shouldn't decide it. I think ext/standard belongs in the global namespace, so I'd move the classes there.
I also agree the names should say what the classes do, without the algorithm. Some options:
- StrSetMatcher, StrSetReplacer, StrSetMatch
- LiteralSetMatcher, LiteralSetReplacer, LiteralSetMatch
- StrSet for matching and StrMap for replacing
Which reads best to you?
Andrew, my goal isn't a new interface but a new mechanism: build the automaton once and apply it to many texts. A function can't keep it between calls, so it needs an object. Whether it pays off depends on how often the dictionary is reused, and only the caller knows that. Take 1,469 bot patterns on User-Agents. A prepared object is 11-12 times faster than the fastest existing method. Building it for a single call is 27-31 times slower. So I wouldn't let str_replace() or strtr() pick it on their own. A shortcut for very small dictionaries can go into the classes later without an API change.
Quoted text · 6 lines
Hi
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\Xoshiro256StarStarorUri\Rfc3986\Uri).I have to disagree with this bit, though. The fundamental functionality which these methods provide is string matching and replacement. The use of Aho-Corasick to implement this is an implementation detail which users should not need to be concerned with, and which PHP should be able to change if a better implementation is found. (By way of example: the standard sorting function is called
sort(), not quicksort().)Yes. I acknowledge that myself in the literal sentence that follows after the part you quoted. My point about “this is a specific type of matching that is being performed by those classes” stands though, and I believe the classes should be renamed.
Best regards
Tim Düsterhus
--
Best regards,
Artem Ukrainskiy