https://github.com/purplebooth/encapsulation-traits
Breaking Encapsulation with traits in PHP
https://github.com/purplebooth/encapsulation-traits
oop php traits
Last synced: 4 months ago
JSON representation
Breaking Encapsulation with traits in PHP
- Host: GitHub
- URL: https://github.com/purplebooth/encapsulation-traits
- Owner: PurpleBooth
- Created: 2017-08-06T22:41:29.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-10-01T20:10:16.000Z (about 1 year ago)
- Last Synced: 2025-03-25T11:49:50.222Z (8 months ago)
- Topics: oop, php, traits
- Language: PHP
- Homepage: https://dev.to/billiecodes/breaking-encapsulation-with-traits-in-php
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Breaking Encapsulation with traits in PHP
=========================================
Traits in PHP are dangerous because they allow the accidental breaking of encapsulation, for no real gain. In this
example you can see an example of traits vs an invokable class, you could use any `callable` type here for the same
effect. You can avoid this by being careful and not setting any member variables in traits, but everyone makes mistakes,
so why risk it, when the encapsulation comes for free with `callable` types?
Run it using
```
composer run
```
It requires PHP 7.1 or greater.