cleaner way to print stack traces?

This is a discussion on cleaner way to print stack traces? within the PHP Language forums, part of the PHP Programming Forums category; Hi, I'm using PHP 4.4.4 witih Apache 2 on Linux. I recently discovered the debug_backtrace() statement. However, ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-10-2007
laredotornado@zipmail.com
 
Posts: n/a
Default cleaner way to print stack traces?

Hi,

I'm using PHP 4.4.4 witih Apache 2 on Linux. I recently discovered
the debug_backtrace() statement. However, when I run the command,

var_dump(debug_backtrace());

what is printed out is a mess. See below. What is a cleaner way of
printing out stack traces. I like the way Java does it. Anyway to
emulate that?

Thanks, - Dave

array(4) { [0]=> array(4) { ["file"]=> string(65) "/usr/local/apache2/
htdocs/refillingstation/custom_product_fns.php" ["line"]=> int(184)
["function"]=> string(10) "executesql" ["args"]=> array(1) { [0]=>
&string(133) "UPDATE ORDER_FORM_CARTRIDGES SET PRICE = ROUND(3, 2),
RETAIL_PRICE = ROUND(4, 2) WHERE P.PRODUCT_ID = 32647) WHERE
PRODUCT_ID = 32647" } } [1]=> array(4) { ["file"]=> string(65) "/usr/
local/apache2/htdocs/refillingstation/
custom_product_fns.php" ["line"]=> int(148) ["function"]=> string(17)
"updatecustomprice" ["args"]=> array(7) { [0]=> &string(1) "6" [1]=>
&string(1) "2" [2]=> &string(6) "C4844A" [3]=> &string(9) "#10
Black" [4]=> &float(3) [5]=> &float(4) [6]=> &string(0) "" } } [2]=>
array(4) { ["file"]=> string(96) "/usr/local/apache2/htdocs/
refillingstation/admin/custom_prices/
import_custom_prices_response.php" ["line"]=> int(24) ["function"]=>
string(19) "updatecustompricing" ["args"]=> array(2) { [0]=>
&string(14) "/tmp/php7TxSi7" [1]=> &string(1) "2" } } [3]=> array(4)
{ ["file"]=> string(66) "/usr/local/apache2/htdocs/refillingstation/
admin/accesscontrol.php" ["line"]=> int(58) ["args"]=> array(1)
{ [0]=> string(96) "/usr/local/apache2/htdocs/refillingstation/admin/
custom_prices/import_custom_prices_response.php" } ["function"]=>
string(7) "include" } }

Reply With Quote
  #2 (permalink)  
Old 08-10-2007
Rik
 
Posts: n/a
Default Re: cleaner way to print stack traces?

On Fri, 10 Aug 2007 22:08:38 +0200, laredotornado@zipmail.com
<laredotornado@zipmail.com> wrote:

> Hi,
>
> I'm using PHP 4.4.4 witih Apache 2 on Linux. I recently discovered
> the debug_backtrace() statement. However, when I run the command,
>
> var_dump(debug_backtrace());
>
> what is printed out is a mess. See below. What is a cleaner way of
> printing out stack traces. I like the way Java does it. Anyway to
> emulate that?


No idea how Java does it. In PHP 5 (you should upgrade anyway) we have
debug_print_backtrace(). Easily recreated using some loop &
debug_backtrace() itself I'd think. It's also in PHP_Compat:
<http://pear.php.net/manual/en/package.php.php-compat.components.php>
--
Rik Wasmus
Reply With Quote
  #3 (permalink)  
Old 08-10-2007
ELINTPimp
 
Posts: n/a
Default Re: cleaner way to print stack traces?

On Aug 10, 4:08 pm, "laredotorn...@zipmail.com"
<laredotorn...@zipmail.com> wrote:
> Hi,
>
> I'm using PHP 4.4.4 witih Apache 2 on Linux. I recently discovered
> the debug_backtrace() statement. However, when I run the command,
>
> var_dump(debug_backtrace());
>
> what is printed out is a mess. See below. What is a cleaner way of
> printing out stack traces. I like the way Java does it. Anyway to
> emulate that?
>
> Thanks, - Dave
>
> array(4) { [0]=> array(4) { ["file"]=> string(65) "/usr/local/apache2/
> htdocs/refillingstation/custom_product_fns.php" ["line"]=> int(184)
> ["function"]=> string(10) "executesql" ["args"]=> array(1) { [0]=>
> &string(133) "UPDATE ORDER_FORM_CARTRIDGES SET PRICE = ROUND(3, 2),
> RETAIL_PRICE = ROUND(4, 2) WHERE P.PRODUCT_ID = 32647) WHERE
> PRODUCT_ID = 32647" } } [1]=> array(4) { ["file"]=> string(65) "/usr/
> local/apache2/htdocs/refillingstation/
> custom_product_fns.php" ["line"]=> int(148) ["function"]=> string(17)
> "updatecustomprice" ["args"]=> array(7) { [0]=> &string(1) "6" [1]=>
> &string(1) "2" [2]=> &string(6) "C4844A" [3]=> &string(9) "#10
> Black" [4]=> &float(3) [5]=> &float(4) [6]=> &string(0) "" } } [2]=>
> array(4) { ["file"]=> string(96) "/usr/local/apache2/htdocs/
> refillingstation/admin/custom_prices/
> import_custom_prices_response.php" ["line"]=> int(24) ["function"]=>
> string(19) "updatecustompricing" ["args"]=> array(2) { [0]=>
> &string(14) "/tmp/php7TxSi7" [1]=> &string(1) "2" } } [3]=> array(4)
> { ["file"]=> string(66) "/usr/local/apache2/htdocs/refillingstation/
> admin/accesscontrol.php" ["line"]=> int(58) ["args"]=> array(1)
> { [0]=> string(96) "/usr/local/apache2/htdocs/refillingstation/admin/
> custom_prices/import_custom_prices_response.php" } ["function"]=>
> string(7) "include" } }


Assuming you are outputting to a browser...you could always do:
echo "<pre>";
var_dump(debug_backtrace());
echo "</pre>";

That should work...

Reply With Quote
  #4 (permalink)  
Old 08-10-2007
Moot
 
Posts: n/a
Default Re: cleaner way to print stack traces?

On Aug 10, 4:45 pm, ELINTPimp <smsi...@gmail.com> wrote:
> On Aug 10, 4:08 pm, "laredotorn...@zipmail.com"
>
>
>
> <laredotorn...@zipmail.com> wrote:
> > Hi,

>
> > I'm using PHP 4.4.4 witih Apache 2 on Linux. I recently discovered
> > the debug_backtrace() statement. However, when I run the command,

>
> > var_dump(debug_backtrace());

>
> > what is printed out is a mess. See below. What is a cleaner way of
> > printing out stack traces. I like the way Java does it. Anyway to
> > emulate that?

>
> > Thanks, - Dave

>
> > array(4) { [0]=> array(4) { ["file"]=> string(65) "/usr/local/apache2/
> > htdocs/refillingstation/custom_product_fns.php" ["line"]=> int(184)
> > ["function"]=> string(10) "executesql" ["args"]=> array(1) { [0]=>
> > &string(133) "UPDATE ORDER_FORM_CARTRIDGES SET PRICE = ROUND(3, 2),
> > RETAIL_PRICE = ROUND(4, 2) WHERE P.PRODUCT_ID = 32647) WHERE
> > PRODUCT_ID = 32647" } } [1]=> array(4) { ["file"]=> string(65) "/usr/
> > local/apache2/htdocs/refillingstation/
> > custom_product_fns.php" ["line"]=> int(148) ["function"]=> string(17)
> > "updatecustomprice" ["args"]=> array(7) { [0]=> &string(1) "6" [1]=>
> > &string(1) "2" [2]=> &string(6) "C4844A" [3]=> &string(9) "#10
> > Black" [4]=> &float(3) [5]=> &float(4) [6]=> &string(0) "" } } [2]=>
> > array(4) { ["file"]=> string(96) "/usr/local/apache2/htdocs/
> > refillingstation/admin/custom_prices/
> > import_custom_prices_response.php" ["line"]=> int(24) ["function"]=>
> > string(19) "updatecustompricing" ["args"]=> array(2) { [0]=>
> > &string(14) "/tmp/php7TxSi7" [1]=> &string(1) "2" } } [3]=> array(4)
> > { ["file"]=> string(66) "/usr/local/apache2/htdocs/refillingstation/
> > admin/accesscontrol.php" ["line"]=> int(58) ["args"]=> array(1)
> > { [0]=> string(96) "/usr/local/apache2/htdocs/refillingstation/admin/
> > custom_prices/import_custom_prices_response.php" } ["function"]=>
> > string(7) "include" } }

>
> Assuming you are outputting to a browser...you could always do:
> echo "<pre>";
> var_dump(debug_backtrace());
> echo "</pre>";
>
> That should work...


On top of the <pre></pre> recommendation, I'd also recommend using
print_r instead of var_dump. At least for me, I find it presents a
much cleaner output.

Reply With Quote
  #5 (permalink)  
Old 08-11-2007
C.
 
Posts: n/a
Default Re: cleaner way to print stack traces?

On 10 Aug, 21:08, "laredotorn...@zipmail.com"
<laredotorn...@zipmail.com> wrote:
> Hi,
>
> I'm using PHP 4.4.4 witih Apache 2 on Linux. I recently discovered
> the debug_backtrace() statement. However, when I run the command,
>
> var_dump(debug_backtrace());
>
> what is printed out is a mess. See below.


So write a program to format it nicely.

> What is a cleaner way of
> printing out stack traces. I like the way Java does it. Anyway to
> emulate that?


It doesn't - someone's written their own rendering tool to format it
nicely.

C.

Reply With Quote
  #6 (permalink)  
Old 08-11-2007
Carl Vondrick
 
Posts: n/a
Default Re: cleaner way to print stack traces?

laredotornado@zipmail.com wrote:
> what is printed out is a mess. Â*See below. Â*What is a cleaner way of
> printing out stack traces. Â*I like the way Java does it. Â*Anyway to
> emulate that?

Check out the xdebug extension.
Reply With Quote
  #7 (permalink)  
Old 08-13-2007
Toby A Inkster
 
Posts: n/a
Default Re: cleaner way to print stack traces?

Carl Vondrick wrote:
> laredotornado@zipmail.com wrote:
>
>> what is printed out is a mess. Â*See below. Â*What is a cleaner way of
>> printing out stack traces. Â*I like the way Java does it. Â*Anyway to
>> emulate that?

>
> Check out the xdebug extension.


For PHP 5, check out the link in my signature.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 53 days, 11:39.]

PHP Debugging with Style -OR- How I Learned to Stop Worrying and Love the Bug
http://tobyinkster.co.uk/blog/2007/0...ng-with-style/
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:02 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0