hassankhan / config

Config is a lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files
MIT License
971 stars 136 forks source link

testing nested key `->has` on unmatched structure #159

Open krills opened 1 year ago

krills commented 1 year ago

Assuming a config like {"foo": "bar"} Testing $config->has('foo.bar.baz') will throw PHP Fatal error: Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array, string given in /.../vendor/hassankhan/config/src/AbstractConfig.php:127

A simple fix to make has() return expected false in this case could be to add is_array($root) && .. before running the array_key_exists($segment, $root) statement