What is the difference between a Readonly Property (PHP 8.1) and a Readonly Class (PHP 8.2)?
Last updated
A readonly property (PHP 8.1) is declared per property. It must be typed, has no default, and can be written once from inside the class (usually the constructor). Later writes throw an
Error.A readonly class (PHP 8.2,
readonly class Point {}) makes every instance property readonly. It forbids untyped, static and dynamic properties, and child classes must also bereadonly.The class form is essentially shorthand for fully immutable objects like value objects and DTOs.
- https://en.wikipedia.org/wiki/PHP
- https://lemon.io/for-developers/php-developer-jobs/
- https://lan-portal.uob.edu.ly/visit/BOOK/529X432U02/modern-php_new__features_and_good-practices.pdf
- https://lan-portal.uob.edu.ly/upload/MD/D57953S372/modern-php__new_features_and__good__practices.pdf
- https://news.ycombinator.com/item?id=30786927
- https://kvnc-inc.medium.com/solid-principles-in-php-1c41069e9af6
- https://www.shkodenko.com/
- https://confoo.ca/en/2024/sessions