smuuf / strict-object
Just a simple strict-object trait.
Installs: 650
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/smuuf/strict-object
Requires
- php: ^7.4|^8
Requires (Dev)
- nette/tester: ^2.3
- phpstan/phpstan: ^0.12.67
This package is auto-updated.
Last update: 2025-10-22 03:01:38 UTC
README
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
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 use \Smuuf\StrictObject; require __DIR__ . '/../bootstrap.php'; class Whatever { use StrictObject; public $someProperty; } $obj = new Whatever; $obj->someProperty = 1; // Ok. echo $obj->someProperty; // Ok. // But - and hold on to your hats... $obj->bogusProperty = 1; // Throws \LogicException. echo $obj->bogusProperty; // Throws \LogicException.