PHPackages                             alkaupp/readonly - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. alkaupp/readonly

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

alkaupp/readonly
================

A trait to provide readonly public properties

1.1(5y ago)0196[1 PRs](https://github.com/alkaupp/readonly/pulls)MITPHPPHP ^8.0CI failing

Since Dec 24Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/alkaupp/readonly)[ Packagist](https://packagist.org/packages/alkaupp/readonly)[ RSS](/packages/alkaupp-readonly/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

Installation
------------

[](#installation)

```
composer require alkaupp/readonly
```

Introduction
------------

[](#introduction)

Do you wish to create data objects but don't want to maintain getter methods in your code? It may be reasonable to create those classes with public properties but also restrict write operations to those properties.

This library tries to tackle that problem by offering a Readonly trait that allows you to write your data classes with private properties and still allow you to access them.

The trait prevents reassignments to your private properties. To gain full immutability you'll have to use immutable objects.

```
