Forum Moderators: coopster
All works well so far, apart from the templates!
In my gallery.php file I have
include("header.php")
*Gallery Code*
include("footer.php")
Somehow, only the includes after the gallery code are executed - anything before causes a redefining conflict within the gallery code. I have spent almost 10 hours trying to find where, but can't.
My question is, is there any way to clear all the variables and the functions in php? I would like the script to include header.php, then clear the variables/functions from that file and just keep the output from it.
Any help would be great, as I am REALLY stuck
include("header.php");
print '<pre>';
$arr = get_defined_vars() [php.net];
print_r($arr);
$arr = get_defined_functions() [php.net];
print_r($arr);
print '</pre><hr />';
*Gallery Code*
print '<pre>';
$arr = get_defined_vars() [php.net];
print_r($arr);
$arr = get_defined_functions() [php.net];
print_r($arr);
print '</pre><hr />';
include("footer.php");
Let's discuss the variables first. Without some form of variable checking, you would be eliminating all variables, including the
$GLOBALSfor the rest of your script, which is probably not what you want happening! You would no longer have access to the
$_POST,
$_GET, etc. variables! Therefore, you will need to build some type of logic into the foreach [php.net] loop below to
unsetonly those variables that you truly want unset.
$arr = get_defined_vars();
foreach (array_keys($arr) as $key) {
unset($arr[$key]); // WARNING: unsets ALL variables!
}
The user-defined functions are a bit easier to
unset. PHP has separated them from the
internalfunctions in a multi-dimensional array with a key of
'user'.
$arr = get_defined_functions();
foreach (array_keys($arr['user']) as $function) {
unset($arr['user'][$function]);
}
I have come across an interesting problem though when I include the files like this instead:
include("http://localhost/header.php")
*Gallery Code*
include("http://localhost/footer.php")
Adding the [localhost...] in seems to include all of the file fine, but it thinks I am "logged out" in the header/footer files - and doesn't remember my session.
Is there any way to find out names of conflicting variables with a script?
I have gotten xdebug [xdebug.org] to work, but haven't really used it for debugging. You might get what you need from doing a stack trace (see the documentation). You may well need to debug interactively, watching specific variables, and that might take some time. One thing that's not particularly clear from the Xdebug site is that the debugger client for interactive debugging uses an interface based on the GDB debugger, which is documented here [gnu.org]
Other debuggers,
- one is packaged with ActiveState Kommodo - this one worked great for me way back when, but I haven't had a working copy of Komodo in a long time (and it costs money).
- dbg [dd.cron.ru] - I've never managed to get this one to work at all.