Re: included variables in a class function
| From: | daniel at electroteque dot org | Date: | Thu, 22 May 2003 03:23:19 +0000 |
| Subject: | Re: included variables in a class function | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-148495@lists.php.net to get a copy of this message | ||
why not include it outside the function and set $config as a global var
like global $config;
> Ok, this it probably a simple fix that is staring me in the face.
>
> I have a function that takes a variable and then includes a config file
> that contains a list of array items. It then does a foreach loop to
> find all the indexes that matches the variable passed to the function
> and then gives puts that indexes value in the appropriate class
> variable for use later.
>
> sounds all good and everything but...the foreach loop gave an error
> saying that the variable passed to it was not an array. after adding an
> echo to see what is being passed i noticed that its not seeing the
> arrays in the included file. Does anyone here have any idea why this
> wouldn't work? It seems fairly basic in form so I am completely stumped
> as to why the array variables in the included file are not accessible
> in the function.
>
> here is an example of what im talking about.
>
> Here is an example of my config file:
>
> <?php
>
> $config[blarg][foo]= 'some value';
> $config[blarg][goo]= 'some other value';
> $config[scooby][doo]= 'wik';
> $config[blarg][too]= 'also wik';
>
> ?>
>
> and here is the function:
> <?php
> function config($func)
> {
>
> require ("path/to/config/php"); // NOTE: I have
already made certain
>
> that the file is successfully being included
> echo $config[blarg][foo]; /* Here is
a basic example. this echo
> will not display anything because the
>
variable acts like its not set even though i just included a
> file with that variable.*/
>
> foreach($config as $key => $k2) { // I included this
even though a
> simple echo demonstrates my point.
> foreach($k2 as $key2 => $value) {
>
>
> if($key2==$func)
> {
> $this->$key= $value;
> }
>
> }
> }
> }
> ?>
>
> Any help or ideas would be much appreciated, seeing how this had gummed
> up my schedule quick a bit :P
>
>
> -Nathan Kline
> [o÷<] Man in the Box
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php