https://github.com/simplecomplex/php-explorable
Foreach'ing protected members made simple
https://github.com/simplecomplex/php-explorable
Last synced: about 1 year ago
JSON representation
Foreach'ing protected members made simple
- Host: GitHub
- URL: https://github.com/simplecomplex/php-explorable
- Owner: simplecomplex
- License: mit
- Created: 2020-06-19T14:06:08.000Z (about 6 years ago)
- Default Branch: develop
- Last Pushed: 2021-04-19T10:32:43.000Z (about 5 years ago)
- Last Synced: 2025-02-16T04:42:40.476Z (over 1 year ago)
- Language: PHP
- Size: 49.8 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# (PHP) Explorable
composer namespace: simplecomplex/**explorable**
## Foreach'ing protected members made simple
An interface, base class and traits making it a breeze to expose a class'
protected members.
Extending `Explorable` facilitates:
- `isset()`
- `count()`
- `foreach (...`
- `var_dump()`
- `toObject()`, `toArray()`
- `json_encode()`
## Usage
### Class declaring it's properties
Property names hardcoded in constant `EXPLORABLE_VISIBLE`.
```php
true,
'bar' => true,
];
protected string $foo;
protected string $bar;
}
```
### Class relying on property table discovery
The properties will be discovered on-demand, via `explorablePrepare()`.
All instance vars must be nullable and declared as null
(`protected ?string $foo = null;`).
Otherwise risk of getting "_::$foo must not be accessed before initialization_"
error, or the instance vars simply won't get discovered (because not set to a
value (null)).
```php