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 3850606
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:02:08+00:00 2026-05-19T17:02:08+00:00

I am building a Language class for internationalization, and I would like to access

  • 0

I am building a Language class for internationalization, and I would like to access the properties dynamically (giving the string name), but I don’t know how to do it when dealing with arrays (this is just an example):

class Language {

    public static $languages_cache = array();

    public $index_header_title;

    public $index = array(
        "header" => array(
            "title" => NULL
        )
    );
}

Now I add languages like this:

Language::$languages_cache["en"] = new Language();
Language::$languages_cache["en"]->index_header_title = "Welcome!"; //setting variable
Language::$languages_cache["en"]->index["header"]["title"] = "Welcome!"; //setting array

Function for accessing members dynamically:

function _($member, $lang)
{
    if (!property_exists('Language', $member))
        return "";

    return Language::$languages_cache[$lang]->$member;
}

So, outputting members:

echo _('index_header_title', "en"); //works
echo _('index["header"]["title"]', "en"); //does not work

I would need a way for accessing arrays dynamically.. for public and private via __set() function.
Thank you!

  • 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-19T17:02:09+00:00Added an answer on May 19, 2026 at 5:02 pm

    You could try using a separator flag so that you can parse the array path. The only problem is you are mixing you properties and arrays so that might complicate things.

    You would call your function like this:

    echo _('index.header.title', "en");
    

    And your function would parse the path and return the correct value. Take a look at the array helper in Kohana 3.0. It has the exact function that you want. http://kohanaframework.org/guide/api/Arr#path

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

Sidebar

Related Questions

This project is in PHP, but is fairly language agnostic. I'm building a project
I'm parsing the HTTP_ACCEPT_LANGUAGE header to get users' language and I'm building a class
I am building a multi-language API to query key value stores and I am
We're building a multi-language Drupal stack and one of the concerns we have is
I am building a project involving natural language processing, since the nlp module currently
Is there a programming language suitable for building web applications, that is compiled, strongly-typed,
I'm building a web portal where language content will generally depend on the accept-language
I'm considering building a visual programming language , akin to Scratch , for use
I am considering building an application that is a blend of a dynamic language
I really don't like the concept of opening my SQL server(s) to the internet

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.