note 118167 added to function.debug-print-backtrace

From: Date: Sun, 18 Oct 2015 18:59:57 +0000
Subject: note 118167 added to function.debug-print-backtrace
Groups: php.notes 
Request: Send a blank email to php-notes+get-203980@lists.php.net to get a copy of this message
This code will give you a simple horizontal stack trace to assist debugging: <?php class A { public function testA() { echo "<LI>Class A.testA ----??"; echo "<LI>".$this->whoDidThat(); } public function whoDidThat() { $who=debug_backtrace(); $result=""; $count = 0; $last=count($who); foreach($who as $k=>$v) { if ($count++ > 0) { $x=""; if ( $count>2) { $x=">"; } $result="[line".$who[$k]['line']."]".$who[$k]['class'].".".$who[$k]['function'].$x.$result; } } return $result; } } class B extends A { public function testB() { echo "<LI>Class B.testB"; echo "<LI>".$this->whoDidThat(); } public function testA() { echo "<LI>Class testB.testA ---- Y"; echo "<LI>".$this->whoDidThat(); } } class C { public function test() { echo "<HR>"; $b=new B(); echo "<HR>Class C calling B.testA"; $b->testA(); } } $c=new C(); $c->test(); echo debug_print_backtrace(); ?> When run you get Class C calling B.testA *Class testB.testA ---- Y *[line45]C.test>[line40]B.testA ---- Server IP: 72.52.91.14 Probable Submitter: 90.196.102.196 ---- Manual Page -- http://php.net/manual/en/function.debug-print-backtrace.php Edit -- https://master.php.net/note/edit/118167 Del: integrated -- https://master.php.net/note/delete/118167/integrated Del: useless -- https://master.php.net/note/delete/118167/useless Del: bad code -- https://master.php.net/note/delete/118167/bad+code Del: spam -- https://master.php.net/note/delete/118167/spam Del: non-english -- https://master.php.net/note/delete/118167/non-english Del: in docs -- https://master.php.net/note/delete/118167/in+docs Del: other reasons-- https://master.php.net/note/delete/118167 Reject -- https://master.php.net/note/reject/118167 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#203980) next »