diff options
author | Andrew Dolgov <[email protected]> | 2021-11-18 07:32:28 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-11-18 07:32:28 +0300 |
commit | 63ec5a89657bb7f9650582b96e0bb255a0889b48 (patch) | |
tree | 074b61eedd7304ba1d8d7deec01d26973ef8e6b8 /vendor/chillerlan/php-settings-container/README.md | |
parent | 3a3fde1a2e0beac6d179c6449eaad726100710d7 (diff) | |
parent | 2d830c6281c19a7ee29cd379f5aedc82deef3775 (diff) |
Merge branch 'wip-phpstan-level6'
Diffstat (limited to 'vendor/chillerlan/php-settings-container/README.md')
-rw-r--r-- | vendor/chillerlan/php-settings-container/README.md | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/vendor/chillerlan/php-settings-container/README.md b/vendor/chillerlan/php-settings-container/README.md index 7d0ccf09d..f3bb26c5e 100644 --- a/vendor/chillerlan/php-settings-container/README.md +++ b/vendor/chillerlan/php-settings-container/README.md @@ -51,8 +51,8 @@ Profit! ## Usage -The `SettingsContainerInterface` (wrapped in`SettingsContainerAbstract` ) provides plug-in functionality for immutable object variables and adds some fancy, like loading/saving JSON, arrays etc. -It takes iterable as the only constructor argument and calls a method with the trait's name on invocation (`MyTrait::MyTrait()`) for each used trait. +The `SettingsContainerInterface` (wrapped in`SettingsContainerAbstract` ) provides plug-in functionality for immutable object properties and adds some fancy, like loading/saving JSON, arrays etc. +It takes an `iterable` as the only constructor argument and calls a method with the trait's name on invocation (`MyTrait::MyTrait()`) for each used trait. ### Simple usage ```php @@ -61,6 +61,13 @@ class MyContainer extends SettingsContainerAbstract{ protected $bar; } ``` +Typed properties in PHP 7.4+: +```php +class MyContainer extends SettingsContainerAbstract{ + protected string $foo; + protected string $bar; +} +``` ```php // use it just like a \stdClass @@ -78,6 +85,8 @@ $container->fromJSON('{"foo": "what", "bar": "foo"}'); $container->toArray(); // -> ['foo' => 'what', 'bar' => 'foo'] // or JSON $container->toJSON(); // -> {"foo": "what", "bar": "foo"} +// JSON via JsonSerializable +$json = json_encode($container); // -> {"foo": "what", "bar": "foo"} //non-existing properties will be ignored: $container->nope = 'what'; |