1

I use var_dump to debug some php scripts locally where I have php 5.6 installed and it formats beautifully on all browsers.

array (size=1)
  0 => 
    object(WP_Post)[1173]
      public 'ID' => int 33
      public 'post_author' => string '1' (length=1)
      public 'post_date' => string '2018-01-11 17:26:22' (length=19)
      public 'post_date_gmt' => string '2018-01-11 23:26:22'(length=19)

When I upload the same file to a production box with php 7, the output is there, but the format is gone! any reason or clue why this is happening?

array(1) { [0]=> object(stdClass)#1162 (3) { ["ID"]=> string(2) "61" ["post_title"]=> str
2
  • 1
    I've noticed that I have XDebug installed locally where not remotely, could that be the reason? Commented Jan 23, 2018 at 17:49
  • Yes, it's almost certainly because of xdebug. In fact, if you view the page source on your local version, you'll probably see xdebug specific markup. <pre class='xdebug-var-dump' dir='ltr'>, etc. PHP 7 is not to blame, that's just a coincidence. Commented Jan 23, 2018 at 18:26

2 Answers 2

5

That "beautiful" format is probably because of Xdebug.

But, you can always use <pre> tags.

<?php
    echo "<pre>";
    var_dump($var);
    echo "</pre>";

It's not the same, but will help.

And remember, Xdebug shouldn't be installed/activated on production environment.

Sign up to request clarification or add additional context in comments.

Comments

-1

XDebug was the main reason! Since I am using Amazon Linux with PHP7, XDebug is not installed by default, so as soon as you install XDebug, var_dump outputs the readable version of the text.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.