Skip to main content

PHP 8.2 readonly Classes Reduce Boilerplate

PHP 8.2 introduced readonly as a class-level modifier. Every property in a readonly class is implicitly readonly — perfect for value objects.Combined with constructor property prom…

April 16, 2026 PHP chris 1 min read Architecture

Article takeaway

PHP 8.2 introduced readonly as a class-level modifier. Every property in a readonly class is implicitly readonly — perfect for value objects.Combined with constructor property prom…

PHP 8.2 introduced readonly as a class-level modifier. Every property in a readonly class is implicitly readonly — perfect for value objects.

Combined with constructor property promotion you get one-line value objects: readonly class Money { public function __construct(public int $cents, public string $currency) {} }.

The constraint: properties can be assigned exactly once, from inside the declaring class. Cloning a readonly object still works via __clone() mutation.

Share X / Twitter LinkedIn

Leave a comment

Related Posts