PHP Config file loader class
Mainly performance improvements?


There doesn't seem to be much oppurtunity for performance improvements. This class basically consists of (1) loading and parsing the configuration and (2) accessing data. For loading, parse_ini_file and json_decode are builtin methods so unless you write your own parser from scratch, you won't make this any faster. And accessing data is basically a single condition checking and an array lookup, not much to improve there either.

However, here is a different kind of suggestion. You probably want to make sure that $filepath in the constructor is restricted to specific directories, for example your web root or better, a subfolder of that. That also means checking for attempts to escape from the restricted directory, e.g. $filepath does not have components like ../. I can easily imagine an attack where a malicious user gets to place a custom php script in /tmp and then (if you have some other vulnerability in your other code) manages to call new Config('/tmp/attack.php'). Then you have an arbitrary maclicous script executing with the priviliges of your website. Ouch.