/php/pear/PHP/Compat/Function/debug_print_backtrace.php

https://gitlab.com/trang1104/portable_project · PHP · 67 lines · 26 code · 8 blank · 33 comment · 2 complexity · 138022391a8a6ba516a34deedfa27a8f MD5 · raw file

  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP Version 4 |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1997-2004 The PHP Group |
  6. // +----------------------------------------------------------------------+
  7. // | This source file is subject to version 3.0 of the PHP license, |
  8. // | that is bundled with this package in the file LICENSE, and is |
  9. // | available at through the world-wide-web at |
  10. // | http://www.php.net/license/3_0.txt. |
  11. // | If you did not receive a copy of the PHP license and are unable to |
  12. // | obtain it through the world-wide-web, please send a note to |
  13. // | license@php.net so we can mail you a copy immediately. |
  14. // +----------------------------------------------------------------------+
  15. // | Authors: Laurent Laville <pear@laurent-laville.org> |
  16. // | Aidan Lister <aidan@php.net> |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: debug_print_backtrace.php,v 1.3 2005/08/17 02:58:09 aidan Exp $
  20. /**
  21. * Replace debug_print_backtrace()
  22. *
  23. * @category PHP
  24. * @package PHP_Compat
  25. * @link http://php.net/function.debug_print_backtrace
  26. * @author Laurent Laville <pear@laurent-laville.org>
  27. * @author Aidan Lister <aidan@php.net>
  28. * @version $Revision: 1.3 $
  29. * @since PHP 5
  30. * @require PHP 4.3.0 (debug_backtrace)
  31. */
  32. if (!function_exists('debug_print_backtrace')) {
  33. function debug_print_backtrace()
  34. {
  35. // Get backtrace
  36. $backtrace = debug_backtrace();
  37. // Unset call to debug_print_backtrace
  38. array_shift($backtrace);
  39. // Iterate backtrace
  40. $calls = array();
  41. foreach ($backtrace as $i => $call) {
  42. $location = $call['file'] . ':' . $call['line'];
  43. $function = (isset($call['class'])) ?
  44. $call['class'] . '.' . $call['function'] :
  45. $call['function'];
  46. $params = '';
  47. if (isset($call['args'])) {
  48. $params = implode(', ', $call['args']);
  49. }
  50. $calls[] = sprintf('#%d %s(%s) called at [%s]',
  51. $i,
  52. $function,
  53. $params,
  54. $location);
  55. }
  56. echo implode("\n", $calls);
  57. }
  58. }
  59. ?>