I've got a CI Library which loads translatable content from an XML file into a class, and the class has a magic __get method which checks if that property is defined when it is referenced, returning the localised key if so, or the keyname plus '_#' to let me know that translation is missing if not.
All cool.
However, because this all depends on properties on an object, I get lots of 'notice: undefined etc..' warnings when I'm running in debug (E_ALL), and it's annoying. I don't want to disable notices, but i do want to know how to disable this inside this particular library (if possible). I could put @ in front of every call to the class, but again, that's pretty horrible too.
Any tips?
Simplified code snippets below:
class MY_Translation
{
function _get_keys($lang) {
// load xml translations, could split this into different files..
$translations = new DOMDocument();
$translations->load($_SERVER['DOCUMENT_ROOT']."/xml/translations.xml");
if ($translations) {
$words = $translations->getElementsByTagName("word");
$count = 0;
foreach( $words as $word ){
$name = $word->getAttribute('name');
$trans = $word->childNodes;
if ($trans->length > 0) {
for($i = 0; $i < $trans->length; $i++) {
$child = $trans->item($i);
if ($child->nodeName == $lang) {
$this->$name = $child->nodeValue;
}
}
}
}
}
}
function __get($key){
if (property_exists('MY_Translation',$this->$key)) {
return $this->$key;
} else {
return $key."_#";
}
}
}
XML (just for reference, so it's clear what's happening):
<?xml version="1.0" encoding="UTF-8"?>
<words>
<word name="thing">
<en>thing en</en>
<pt>thing pt</pt>
</word>
</words>