So I'm developing an application which is using an IoC container. Now I need some helper methods for array manipulation like set, get, etc. I see two possible ways to go:
- Using a class with static methods.
- Using a class with non-static methods registered in the IoC container.
When using method 1, it will look something like this:
$arr = array(); // Defining $arr Arr::set($arr, 'a', 'b'); // Sets 'a' => 'b' in $arr echo Arr::get($arr, 'a'); // Outputs 'b'
And using method 2, I will first register a new Arr class in the IoC container and than using it would look something like this:
$arr = array(); // Defining $arr $app['arr']->set($arr, 'a', 'b'); // Sets 'a' => 'b' in $arr echo $app['arr']->get($arr, 'a'); // Outputs 'b'
According to my benchmarks, method 1 is almost twice as fast as method 2. So in terms of performance method 1 is the way to go (I think). But, static methods are generally considered bad practice. So in terms of best practices, I should use method 2 to avoid static methods.
My question is if I should use the IoC container for helper methods or just use the static methods.