Jump to content

Archived

This topic is now archived and is closed to further replies.

cesarhtown

getting/printing variables

Recommended Posts

Hey guys!

This is the situation. I have a script that somebody else wrote. This guy has a main.php page that includes different .php pages. Those .php pages include other .php pages, and those include OTHER .PHP PAGES! in my opinion, the code is a mess! I've been trying my best to come up with the logic of all these pages put together, but it's riduclous... oh well... can anybody help with some kind of function that reads all variables that are passed on/included to the main.php page? it would be nice to enter a function that gives you a list of all the variables that are in play from those pages on main.php somewhere. Please help.

Cesar.

Share this post


Link to post
Share on other sites
i dont think there is anything that you can just tack onto the bottom of your script that will tell you all the $variables you have in your script.

If I'm right, then what you need to do is work through your code logically, and carefully.

Start with main.php.
When you find an include('file.php') go to that file, copy the code and paste it into main.php in place of the include... then do the same for the next include, and the next and the next, and so on.

Eventually you'll have one very large main.php file which is easy to follow through and see what is doing what, and you can then split it down and include parts of it as you want to, rather than how it was put together in the first place.

Share this post


Link to post
Share on other sites
Actually, I think I figured it out. I applied this code to my script:

foreach ($GLOBALS as $k => $v)
{
echo "\$GLOBALS[$k] => $v <br>";
}

That seems to do the trick, except for the variables that are arrays, but I guess I can loop into it, I just don't need them. Thanks for the advice.

Share this post


Link to post
Share on other sites
Use [code]<?php echo '<pre>' . print_r($GLOBALS,true) . '</pre>'; ?>[/code] This will do the "right thing" for the arrays and recursive arrays which exisit in the $GLOBALS array.

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.