Jump to content

How to get snapshoot of variables, calls, etc. with disturbing output stream?


Recommended Posts

I need to debug a php program.  I've tried to use something like:

 

$debuginfo = var_dump(debug_backtrace());

 

and then write $debuginfo  to a text file for later review.

 

The problem I have is that this approach uses the output stream and my program also wants to write to the output stream.  Unfortunately, other programs are using the output stream and dumping dignostic data to the outputstream mesess with the state of the program.

 

Is there a way to get a snapshot of variables and calls without interfering with the output stream?

 

Thanks

 

Mike

 

Link to comment
Share on other sites

Unfortunately var_dump goes stright to the output stream.  What I need is a function that does the same thing by storing to a variable I can then write to a file.

 

Did you actually read my reply?

Link to comment
Share on other sites

Here is what I tried

 

      $a = 1;

      $b = 2;

      $c = 3;

      $snapshot = var_export();

      echo $snapshot;  // will write to file rather than echo when it works

 

 

I assumed I would see a list of variables  ($a, $b and $c) and their values in $snapshot but saw nothing displayed.

 

Keep in mind I may also need the previous program to know how the program got to the point of failure.

 

Thanks

     

Link to comment
Share on other sites

Can't see how var_export does anything for me.  If I know a variable's name I can just write it to a file.  I started out thinking something like vr_dump(debug_backtrace()) might be what I needed. Just can't figure out how to get that data written to a file without mesing with the output stream.

Link to comment
Share on other sites

That was a very helpful suggestion for keeping results from ending up in the output stream.

 

Still, I don't see how you came up with the suggestion to use True as an argument.  I'm using the documentation (version 5.3.6) of debug_backtrace() at:

 

        http://php.net/manual/en/function.debug-backtrace.php

 

Is there a better documentation I should have used?

 

What I'm getting now is understandable but all in one long unformatted string.  Is there an option to format it with some structure when sending the string to a text file?

 

Thanks

Mike

 

 

Link to comment
Share on other sites

Still, I don't see how you came up with the suggestion to use True as an argument.  I'm using the documentation (version 5.3.6) of debug_backtrace() at:

 

        http://php.net/manual/en/function.debug-backtrace.php

 

Is there a better documentation I should have used?

 

Take another look, the true argument is not in debug_backtrace(). It is in var_export(), and I already linked you to that documentation.

Link to comment
Share on other sites

Still, I don't see how you came up with the suggestion to use True as an argument.  I'm using the documentation (version 5.3.6) of debug_backtrace() at:

 

        http://php.net/manual/en/function.debug-backtrace.php

 

Is there a better documentation I should have used?

 

Take another look, the true argument is not in debug_backtrace(). It is in var_export(), and I already linked you to that documentation.

 

As did I in my very first reply.

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.