You are here: Re: Using $GLOBALS « PHP Language « IT news, forums, messages
Re: Using $GLOBALS

Posted by Hilarion on 10/05/71 11:31

> I want to analyse files with arrays in them (language files)
> automatically. Those files are usually included into the code by running
> a
>
> require_once($path);
>
> Now I want to find out what variables (mainly arrays) are in which file
> by parsing through them and requiering them one by one while making an
> array_diff between the $GLOBALS before and afte rthe require_once.
>
> something like that:
>
> function plg_dl_scanlangfiles()
> {
> global $_CONF;
>
> $glob_first = $GLOBALS;
>
> if ($dir = opendir($_CONF['path_language'])) # open directory
> {
> while (false !== ($file = readdir($dir))) # iterate through the files
> {
> if ($file != "." && $file != "..")
> {
> require_once( $_CONF['path_language'] . $file);
> $glob_now = $GLOBALS;
> $glob_diff = array_diff($glob_first, $glob_now);
>
> #include func here that adds contents of $glob_diff to the database
> }
> }
> }
> }
>
> now the strange thing is that $glob_now is identical to $glob_first.
> Is that normal? The file & path are OK. Any ideas? Any better way to do
> this?
>
> Also, $glob_now gets emptied after doing a array_diff! Why? Should it be
> not unchanged? Only $glob_diff should change, no? (running php 5.0.4)


Maybe the problem is caused by $GLOBALS feature. It contains references
to variables, and not values. When you copy the array, you get an array
containing references too. Which means that if some value in $GLOBALS
gets changed, then when you check your copy, you'll see the new value.
Only difference will be in new variables added to the array. It may
also be the cause of strange behavior of array_diff.

I'm not sure if this really is the cause. I do not know if $GLOBALS
does work this way, but this MAY be it.

I always had problems with references in arrays (mostly with references
to arrays in arrays and getting references to array elements) so if
there's someone that knows something more about it and is able to
describe it here using simple language and some examples, then I'll be
grateful.


Hilarion

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация