Re: Pre-RFC: adding a Regex\CompiledRegex class for compiling regular expressions
| From: | Tim Düsterhus | Date: | Sat, 26 Sep 2026 11:02:30 +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-132652@lists.php.net to get a copy of this message | ||
Hi
On 9/25/26 19:03, Juris Evertovskis wrote:
- Why final? Let me add methods while there's nothing in the core.
This is a question that comes up for every new internal (value) class and has been extensively discussed during the design of ext/uri. To give a short summary:
- Allowing inheritance allows to break the assumptions of internal classes, particularly those that store internal state (since you can just bypass the parent constructor).
- It is impossible to correctly construct child classes, particularly those that add additional properties, breaking the expectations for “with-er” style methods.
- Adding additional methods becomes a possible breaking change.
- Liskov Substitution applies not just to the actual API, but also to the expected behavior. For value classes, the expected contract is “what the class does”, making it effectively impossible to override anything.
- WhyThese two are probably a consequence of the initial design of an “opaque” resource object. I agree that it would be reasonable to lift it (when a proper API is designed around the proposed class). Best regards Tim Düsterhus@not-serializable? Serialization would seem as straightforward as for a plain DTO. - Why notreadonly publicfor all params? Inspecting the setup would be useful to build onto this in userland.