Skip to content

Instantly share code, notes, and snippets.

@1234ru
Last active May 9, 2024 14:35
Show Gist options
  • Save 1234ru/1bcafda955294075ac51bda3f9c9a735 to your computer and use it in GitHub Desktop.
Save 1234ru/1bcafda955294075ac51bda3f9c9a735 to your computer and use it in GitHub Desktop.
Для хранения настроек по умолчанию можно использовать то же свойство объекта, которое будет их хранить
class SomeClass {
    private $settings = [
        'a' => 1,
        'b' => 2,
    ];

    function __construct($options)
    {
        $this->settings = array_replace_recursive(
            $options,
            $this->settings
        );
    }
}

Однако в таком случае не выйдет по-простому получить собственно настройки по умолчанию и определить, какие из них изменены.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment