On 2026-09-23 22:01, Gina P. Banyard wrote:
I've currently landed on the following concept design:
```
namespace Regex {
class CompilationError extends Exception {}
/**
* @strict-properties
* @not-serializable
*/
final class CompiledRegex {
public function __construct(
string $pattern,
bool $caseSensitive = true,
bool $greedy = true,
bool $anchor = false,
bool $multiLine = false,
bool $dotMatchesNewLine = false,
bool $ignoreWhitespace = false,
bool $captureOnlyNamedGroups = false,
bool $allowDuplicateSubPatternNames = false,
) {}
}
}
```
Hi!
Great idea!
I've got some stupid questions though:
- Why `final`? Let me add methods while there's nothing in the core.
- Why `@not-serializable`? Serialization would seem as straightforward
as for a plain DTO.
- Why not `readonly public` for all params? Inspecting the setup would
be useful to build onto this in userland.
Regarding points brought up by otters
- +1 for the `Regex` name. And in that case `Pcre\Regex` might be nicer
to avoid duplication and mixups.
- I would also need `fromString` or similar, but no problem to add it
myself for now, as long as it's not fainal.
- I don't buy the objections about the number of the args. These days
there's no problem to write `new Regex($pattern, multiline: true)`.
Fluent builders, enums, constants — those are just workarounds in the
absence of such syntax.
BR,
Juris