OK, this is going to sound stupid, but as I've never had occasion to do this, I'm now lost. It's prolly somethin' extremely easy.
What I am doing is parsing a line (string) that is ";" demilited. I am using explode() to seperate the fields. Now the information is used during the instantiation of db connection objects. The first parameter is what I want to name the object. So, the array is named $params. I want to use $param[0] to name the db object. So if $param[0] = Liberace, I want the to name the object $Liberace.
If there is a way to do this, I'd love to know.
Thanx,
BDKR (TRC)
Naming vars from vars
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You want to take a loop at variable variables I'd post an example but I always manage to get myself really confused with these although it tends to work in the end.
Mac
Mac
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
maybe something like
???
Code: Select all
<?
${$paramї0]} = $paramї1];
?>Being that this is being done inside a loop, I don't think using variable vars will work. At each iteration through the loop, the value of $param[0] is going to change.
So what's going to happen to the name of that object I created the second time through the loop? I'm going to try it anyways and see, but I suspect this isn't going to work.
Later on,
BDKR (TRC)
Code: Select all
# Now open the configuration file
$config_file=file("config.php");
# Iterate through the lines in the file and create the db objects
while(list($key, $val)=each($config_file))
{
$params=explode(";", $val);
$$paramsї0] = new Database('$paramsї1]');
}Later on,
BDKR (TRC)
OK. I didn't really fix it as much as I came up with a different approach. The first thing I did was change the object just a tad bit to include a var called $this->object_name. Then passed it it's name during instantiation.
Now I have an indexed array of connection objects wich when you get down to is is prolly better than an associative array. However, as I still need to know which system each object is associated with, I can just add a method to the object to identify itself with the $this->object_name var.
Yeeeeehawww Fool!
BDKR (TRC)
Now I have an indexed array of connection objects wich when you get down to is is prolly better than an associative array. However, as I still need to know which system each object is associated with, I can just add a method to the object to identify itself with the $this->object_name var.
Yeeeeehawww Fool!
BDKR (TRC)