Jump to content

getting/printing variables


cesarhtown

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.
Link to comment
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.

Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.