Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

how to "pretty print" var dumps

How to make your var dumps/arrays come out a lot nicer for debugging.

PHP Code

<?php 
//Normal Code:

$_SESSION['name'] = "Garry";
$_SESSION['password'] = "insecurePassword";

print_r($_SESSION); 
This outputs

Code
array(2) {
 ["name"]=>
 string(5) "Garry"
 ["password"]=>
 string(16) "insecurePassword"
}

The more eye appealing way to do this would be
PHP Code

<?php 
// Pretty Code

$_SESSION['name'] = "Garry";

$_SESSION['password'] = "insecurePassword";

echo 
"<pre>".print_r($_SESSION, true)."</pre>"; 
This outputs
Code
Array
(
   [name] => Garry
   [password] => insecurePassword
Just get xDebug, it will output it nicely :)
(Mar 29, 2018 01:42 PM)Hexi Wrote:  Just get xDebug, it will output it nicely :)
Installiing an entire extension just to use print_r a few times during debug? No thanks.

Je t'aime
[Image: fpZ5a5g.png]

(Apr 22, 2022 04:39 PM)-Scrub Wrote:  Jokes on you, I'm not smart enough to know what he's talking about.
Setting Content-Type to text/plain does this. Otherwise, as you already did, wrapping the output in <pre>'s is probably the best way to go. Alternatively you might be able to replace \n with <br> by fiddling around with output buffering a bit.
/* No comment */
(Mar 29, 2018 02:58 PM)Nachfolger Wrote:  Installiing an entire extension just to use print_r a few times during debug? No thanks.

Installing an extension dedicated to debugging instead of debugging by outputting information and datas directly on page, well, it actually sounds like a good idea...
(Mar 30, 2018 03:48 PM)Sakuto Wrote:  Installing an extension dedicated to debugging instead of debugging by outputting information and datas directly on page, well, it actually sounds like a good idea...
Maybe for your projects you need this, but I've very rarely needed to use serious debugging methods to figure out my errors or such. I'm also on a shared host, so I don't have an option to install extensions of my choosing.

Not that I would, anyway. I usually find the bugs within my queries or whatever when I take a 10m break and come back.

Je t'aime
[Image: fpZ5a5g.png]

(Apr 22, 2022 04:39 PM)-Scrub Wrote:  Jokes on you, I'm not smart enough to know what he's talking about.
(Apr 1, 2018 06:06 AM)Nachfolger Wrote:  Maybe for your projects you need this, but I've very rarely needed to use serious debugging methods to figure out my errors or such. I'm also on a shared host, so I don't have an option to install extensions of my choosing.

Not that I would, anyway. I usually find the bugs within my queries or whatever when I take a 10m break and come back.

Well, tbh, if you debug on production server, you have problem way more serious than not being able to use debugger.
(Apr 1, 2018 09:55 AM)Sakuto Wrote:  Well, tbh, if you debug on production server, you have problem way more serious than not being able to use debugger.

Can you fuck off? You are the most disrespectful and arrogant asshole I’ve ever met online.

[warn]
(Apr 1, 2018 09:57 AM)yrnGarry Wrote:  Can you fuck off? You are the most disrespectful and arrogant asshole I’ve ever met online.

You should listen to what he has to say and not dismiss him because of his tone. Debugging in production is actually very bad.
/* No comment */
(Apr 1, 2018 09:57 AM)yrnGarry Wrote:  Can you fuck off? You are the most disrespectful and arrogant asshole I’ve ever met online.

He’s right. You shouldn’t do development debugging in a production environment. Have a test/dev, staging (mirror of production), and production environment.
(Apr 1, 2018 11:02 AM)Charger Wrote:  He’s right. You shouldn’t do development debugging in a production environment. Have a test/dev, staging (mirror of production), and production environment.

I didn’t say he was wrong. He negged me because HE didn’t find this helpful and that really annoys me
(Apr 1, 2018 11:03 AM)yrnGarry Wrote:  I didn’t say he was wrong. He negged me because HE didn’t find this helpful and that really annoys me

Well, actually it's more because NONE of your """tutorial""" is useful / right. Telling bullshit and writing tutorial on it is not enough to pretend to be qualified.
(Apr 1, 2018 11:08 AM)yrnGarry Wrote:  You are an asshole, they are aimed towards beginners. If you weren’t a beginner then you should have clicked off you cancerous shit head

Well, let me explain it in simple word.

That's not because they're aimed towards beginners that they can be FALSE and teach them BAD HABITS.
It's even the opposite, that's because they're aimed to beginners that they should be accurate and high quality.

It's simple, don't overestimate your skills.
(Apr 1, 2018 11:10 AM)Sakuto Wrote:  Well, let me explain it in simple word.

That's not because they're aimed towards beginners that they can be FALSE and teach them BAD HABITS.
It's even the opposite, that's because they're aimed to beginners that they should be accurate and high quality.

It's simple, don't overestimate your skills.

It is all correct, and they are actually good habits
(Apr 1, 2018 11:02 AM)Quad Wrote:  You should listen to what he has to say and not dismiss him because of his tone. Debugging in production is actually very bad.
Of course it's bad. But he's the one who mentioned it. Not op, nor I. No one was even talking about debugging in production, unless it was deleted or I missed it.

Je t'aime
[Image: fpZ5a5g.png]

(Apr 22, 2022 04:39 PM)-Scrub Wrote:  Jokes on you, I'm not smart enough to know what he's talking about.


Possibly Related Threads...
Thread / Author Replies Views Last Post
by HackersMar 14, 2025 02:08 PM 6 279 Mar 14, 2025 02:08 PM
Last Post: Zher0
[PHP] by Jeffr0May 31, 2022 11:51 AM 9 412 May 31, 2022 11:51 AM
Last Post: Yoyo95
[PHP] by blackcoder00Aug 8, 2020 03:57 AM 6 208 Aug 8, 2020 03:57 AM
Last Post: Squito