FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Names of URL Parameters
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Names of URL Parameters [message #175455 is a reply to message #175424] Wed, 28 September 2011 18:46 Go to previous messageGo to previous message
tamouse is currently offline  tamouse
Messages: 5
Registered: September 2011
Karma:
Junior Member
Since the question seems directed to debugging, you should know about two functions: print_r and var_dump:

http://us2.php.net/manual/en/function.print-r.php
http://us2.php.net/manual/en/function.var-dump.php

In both of these cases, the standard behaviour is to dump the variable structure straight to the standard output (most likely your browser window/tab). This can be problematic for a few reasons, and can be a security risk if you're not careful.

print_r has a second paramter, which if set to TRUE, will return it's output as a string, which you can sanitize before sending to output thus:

echo "<pre>" . htmlentities(print_r($var,TRUE)) . "</pre>" . PHP_EOL;

This sort of thing will prove invaluable in debugging php code for the newbie.

If you're doing a fair bit of this, you might want to set up a function for debugging, and use a global to turn on/off debugging. Lots of these exist already, some very sophisticated, some very simple.

Extremely simple:

function dbg($var)
{
if ($GLOBALS['DEBUG'])
{
echo "<pre>".print_r($var,TRUE)."</pre>".PHP_EOL;
}
}

And you can set $GLOBALS['DEBUG'] in a number of ways, such as in a common configuration file that is included in your application, or by introducing a DEBUG parameter in the $_REQUEST hash.

Some people (*cough*) go so far as to write a debugger class with all sorts of fancy bells and whistles, such as including the file, function, and line number where the debugging call is made, among others.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: best editor
Next Topic: discussing LeBron 8 PS
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Sep 20 04:33:40 GMT 2024

Total time taken to generate the page: 0.05146 seconds