maexus Posted June 11, 2008 Author Share Posted June 11, 2008 Ok, loaded this in and ran it. It looked promising as I wasn't getting just the usually error. I first tried get("db") Notice: Undefined variable: this->settings in settings.class.php on line 77 Array ( [db] => Array ( ) ) I then tried get("db__host") and get: Array ( [db] => Array ( ) [host] => Array ( ) ) db is a key in the $settings array, a base key. host is a key of db. So the get() function should return the db array, db should appear in the array. This is what the array should look like if the function is working right when using get("db"): Array ( [host] => localhost [username] => root [password] => root [database] => test [prefix] => ) Going back and reviewing the first page, effigy suggested using eval. Any other ideas in that direction as I'm completely dry. Quote Link to comment Share on other sites More sharing options...
grimmier Posted June 11, 2008 Share Posted June 11, 2008 something else to try. taking into consideration eval public function get($variable){ $varArray = explode('__', $variable); $temp_var = "this->settings"; foreach($varArray as $key=>$value) { $temp_var .= "['".$value."']"; } $z = eval("return \$$temp_var;"); return $z; // Or to keep it similar to your first ones. return string // return (isset($z)) ? $z : $z; } } Quote Link to comment Share on other sites More sharing options...
maexus Posted June 11, 2008 Author Share Posted June 11, 2008 Testing this out but I think that does it. It works! Thanks, seriously and thanks to everyone who posted. Quote Link to comment Share on other sites More sharing options...
grimmier Posted June 11, 2008 Share Posted June 11, 2008 glad to hear it. keep me posted, still curious if it will work when stuck into your application. Quote Link to comment Share on other sites More sharing options...
maexus Posted June 11, 2008 Author Share Posted June 11, 2008 Looks good, seems to work fine when I replaced the old get() method. There is an oddity. If there is one too many indexes, it only outputs the first character of the previous index. Like if I select get("db__host__test") and db__host is "LOCALHOST" but the index test doesn't exist, it will return "L". However, if I add another non existent index get("db__host__test__another") it outputs the following error: Fatal error: Cannot use string offset as an array Like I said, an oddity, just a warning for anyone who may use the code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.