Advertisement
Guest User

php back trace

a guest
Oct 26th, 2018
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. class LogAdapter
  2. {
  3.     public static function log($event)
  4.     {
  5.         $bt = debug_backtrace();
  6.         $index = null;
  7.         foreach($bt as $idx => $trace) {
  8.             if($trace['class'] == 'LogAdapter') {
  9.                 $index = $idx;
  10.             }
  11.         }
  12.         echo $event . ' Class : ' . $bt[$index + 1]['class'] . ', line : ', $bt[0]['line'] . ', file : ' . $bt[$index + 1]['file'] . '<br />';
  13.     }
  14. }
  15.  
  16. class TestC
  17. {
  18.     public static function test()
  19.     {
  20.         LogAdapter::log('Event 2');
  21.     }
  22. }
  23.  
  24.  
  25. class TestB {
  26.     public static function test()
  27.     {
  28.         LogAdapter::log('Event 1');
  29.         TestC::test();
  30.         LogAdapter::log('Event 3');
  31.     }
  32.  
  33. }
  34. TestB::test();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement