Skip to content

Use classes with readonly properties more widely#1592

Merged
cpeel merged 12 commits into
DistributedProofreaders:masterfrom
bpfoley:more-dto
Jul 8, 2026
Merged

Use classes with readonly properties more widely#1592
cpeel merged 12 commits into
DistributedProofreaders:masterfrom
bpfoley:more-dto

Conversation

@bpfoley

@bpfoley bpfoley commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

This is more intended to start discussion rather than necessarily to be merged as-is.

As you can see, PHP 8.0's "property constructor promotion" is more of a win in simpler classes that are mostly "data transfer objects", and it saves less boilerplate when there's an inheritance hierarchy, or when some properties have to be explicitly declared.

However, I do like the opportunity to sprinkle more 'readonly' on properties (which says only the constructor can assign to a property, and it can only do it once). Avoiding mutable state makes it a lot easier to reason about classes.

After a couple of fixes, it passes all the smoke tests (and PHPstan is happy).

It's deployed at https://www.pgdp.org/~bfoley/c.branch/more-dto and I did some cursory poking around with the proofreading interface, project search, wordcheck, stats etc.

@cpeel cpeel requested review from 70ray, cpeel, jchaffraix and srjfoo July 1, 2026 23:19
@cpeel cpeel merged commit 5bed046 into DistributedProofreaders:master Jul 8, 2026
12 checks passed
@bpfoley bpfoley deleted the more-dto branch July 9, 2026 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants