Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #3234
| From | sheldonlg <sheldonlg@thevillages.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Names of URL Parameters |
| Date | 2011-09-29 09:15 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <j61rlr$fae$1@dont-email.me> (permalink) |
| References | <Qbseq.173772$wz.21080@en-nntp-08.dc1.easynews.com> <21105381.202.1317235599809.JavaMail.geo-discussion-forums@vbkm14> |
On 9/28/2011 2:46 PM, tamouse wrote:
> 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.
I would use $_SESSION['DEBUG'] instead.
--
Shelly
Back to comp.lang.php | Previous | Next — Previous in thread | Find similar | Unroll thread
Names of URL Parameters "eBob.com" <eBob.com@totallybogus.com> - 2011-09-21 16:56 -0400
Re: Names of URL Parameters The Natural Philosopher <tnp@invalid.invalid> - 2011-09-21 22:06 +0100
Re: Names of URL Parameters Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-09-21 23:46 +0200
Re: Names of URL Parameters "eBob.com" <eBob.com@totallybogus.com> - 2011-09-21 23:27 -0400
Re: Names of URL Parameters "Peter H. Coffin" <hellsop@ninehells.com> - 2011-09-22 07:43 -0500
Re: Names of URL Parameters Richard Damon <news.x.richarddamon@xoxy.net> - 2011-09-22 13:36 -0400
Re: Names of URL Parameters tamouse <tamouse.lists@gmail.com> - 2011-09-28 11:46 -0700
Re: Names of URL Parameters tamouse <tamouse.lists@gmail.com> - 2011-09-28 12:18 -0700
Re: Names of URL Parameters sheldonlg <sheldonlg@thevillages.net> - 2011-09-29 09:15 -0400
csiph-web