Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Immutable Nature of Classes #16

Closed
vidhvath28 opened this issue Oct 4, 2024 · 1 comment
Closed

Immutable Nature of Classes #16

vidhvath28 opened this issue Oct 4, 2024 · 1 comment
Assignees

Comments

@vidhvath28
Copy link

Ensure that other parts of your codebase respect the immutability of these classes. Any modifications that are attempted should either return a new instance or throw an error.

@gustavofreze
Copy link
Member

This is ensured by the following aspects:

  • Final class: The class is marked as final, which prevents inheritance. This means that no one can extend the class and modify its behavior or internal state.

  • Private properties: All properties are declared private, so they cannot be directly modified from outside the class.

  • Use of readonly: The use of the readonly keyword in PHP 8.2 for the Ksuid class ensures that its properties can only be assigned during initialization (in the constructor) and cannot be modified afterward.

  • State mutation-free methods: None of the methods in the class modify the properties after they are defined. All methods simply return values calculated based on the existing state of the instance.

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

No branches or pull requests

2 participants