I need some help with a situation, that I have no ideea how to start with, not even where to look for.
I have a large *.ini file (for language) that I would want to parse only once at the start of a php document and then use the result anywhere in the document.
I think, I need a class, like:
class Language{
private language = array();
function get( $string ){
return $this->language[ $string ];
}
function getLanguage(){
/* get and parse *.ini file once */
$result = array;
/* set language */
$this->language = $result;
}
}
So, in theory, at php document beginning, the class, somehow, calls getLanguage() and set language array
Language::getLanguage();
And then, anywhere in the rest of php document, especially inside other classes (without sending as function param), get certaing language array element without parsing *.ini file again.
class AClass{
function __construct(){
echo Language::get( $certain_string );
}
}
new AClass;
Any advice is well received.
Thanks.
To be able to call a method with :: you need to declare it static.
I think this is what you need. If you need further tuning, let me know.
PS: If you declare
private function __construct(){}andprivate function __clone(){}– it will be a classic Singleton design pattern.