Re: Pre-RFC: adding a Regex\CompiledRegex class for compiling regular expressions
| From: | Tim Düsterhus | Date: | Sat, 26 Sep 2026 10:43:42 +0000 |
| Subject: | Re: Pre-RFC: adding a Regex\CompiledRegex class for compiling regular expressions | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-132649@lists.php.net to get a copy of this message | ||
Hi
On 9/25/26 17:08, Jordi Kroon wrote:
Similarly to backed enums, I also considerFor the prototype I've only added support to use this new class to the preg_split() and preg_grep() functions as they were easy to tweak.Is it by design that this class does not have a__toString()method.
__toString() to be a mistake, because there is generally not a single obvious scalar / string representation, which you also acknowledge yourself: Delimiters would need to be invented out of thin air - and modifiers are not necessarily portable across programming languages or regex engines.
And would you consider adding it? It would potentially allow the stubs for the exiting functions to stay unchanged. This would be similar to what the Uri API is doing, however it would require some sort delimiter generation I suppose.I don't follow the reference to the URI API. It specifically doesn't have a __toString() implementation.
And if we are going that direction, how about we add a ::fromString(),
to make it easier to migrate to this new API? And make use of it's
Validation ability.
That however would make sense to me, but it would likely need a better name, because it's a *specific* string format that is expected.
Best regards
Tim Düsterhus