https://github.com/smuuf/php-strict-object
Just a simple strict-object trait.
https://github.com/smuuf/php-strict-object
Last synced: 2 months ago
JSON representation
Just a simple strict-object trait.
- Host: GitHub
- URL: https://github.com/smuuf/php-strict-object
- Owner: smuuf
- License: mit
- Created: 2021-01-16T12:53:40.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-02-21T16:22:23.000Z (over 4 years ago)
- Last Synced: 2025-02-15T01:30:36.209Z (4 months ago)
- Language: PHP
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Strict Objects for PHP 🌻

Avoid annoying problems caused by PHP being too lax when dealing with undeclared object properties. Let's be more strict. Don't let typos in property names ruin your day ever again. 🌞
## Installation
```bash
composer require smuuf/strict-object
```## Usage
Simple, just `use` the `\Smuuf\StrictObject` trait in your class to make it strict - and to **throw `\LogicException`** when someone tries to **read** or to **write** to an **undeclared property**.
```php
someProperty = 1; // Ok.
echo $obj->someProperty; // Ok.// But - and hold on to your hats...
$obj->bogusProperty = 1; // Throws \LogicException.
echo $obj->bogusProperty; // Throws \LogicException.```