Brent 8/3/2025

Readonly or private(set)

Read Original

This technical article compares PHP's readonly properties (introduced in PHP 8.1) with private(set) asymmetric visibility (from PHP 8.4). It explains how readonly ensures a property is set only once, while private(set) allows public reading but restricts writing to within the class. The author discusses the practical implications for creating structured, typed data objects and reducing boilerplate code.

Readonly or private(set)

Comments

No comments yet

Be the first to share your thoughts!

Browser Extension

Get instant access to AllDevBlogs from your browser

Top of the Week

1
The Beautiful Web
Jens Oliver Meiert 2 votes
2
Container queries are rad AF!
Chris Ferdinandi 2 votes
4
LLM Use in the Python Source Code
Miguel Grinberg 1 votes
5
Wagon’s algorithm in Python
John D. Cook 1 votes