Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6729601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:18:35+00:00 2026-05-26T10:18:35+00:00

I’ve got a CI Library which loads translatable content from an XML file into

  • 0

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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:18:35+00:00Added an answer on May 26, 2026 at 10:18 am

    As you use $this to store the translations, __get is only called on non-existent properties. Change it, the warning you get only notifies you that you’re doing something wrong:

    function __get($key)
    {
        return $key."_#";
    }
    

    That’s really all you need to do.


    Did you mean

    $this->t->$key
    

    instead of

    $this->$key
    

    ?

    Then you would need to fix the assignment as well:

    $this->t->$name = ...
    

    In general, as you check for the property in the __get function you should not see any warning. The warnings show you that you’ve made some error in your program logic, so they are useful and you should not disable them not even for a short part of your code. Disabling warnings is not the solution but fixing the code.

    Let me know if this was helpful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from
I'm parsing an XML file, the creators of it stuck in a bunch social
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.