php - Accessing object properties of type array dynamically -


i building language class internationalization, , access properties dynamically (giving string name), don't know how when dealing arrays (this example):

class language {      public static $languages_cache = array();      public $index_header_title;      public $index = array(         "header" => array(             "title" => null         )     ); } 

now add languages 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 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 need way accessing arrays dynamically.. public , private via __set() function.
thank you!

you try using separator flag can parse array path. problem mixing properties , arrays might complicate things.

you call function this:

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

and function parse path , return correct value. take @ array helper in kohana 3.0. has exact function want. http://kohanaframework.org/guide/api/arr#path


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -