I am having this class.
<?php
class Helper
{
private $config;
public function __construct(array $config)
{
$this->config = $config;
}
public function getVal($key)
{
return $this->config[$key];
}
}
The config is set on boot time and cannot be changed during runtime, so for a specific runtime, the same arguments will always give the same results but we cannot say the same thing about different instances of the program.
Can getVal(string)
be considered a pure function?
Another, non-OOP version of the same functionality would be this:
<?php
function getVal($key){
static $config;
if ($config === null) {
$config = include "config.php";
}
return $config[$key];
}