]> granicus.if.org Git - php/commitdiff
* added debug_backtrace() support to PEAR errors
authorStig Bakken <ssb@php.net>
Thu, 9 Jan 2003 15:14:23 +0000 (15:14 +0000)
committerStig Bakken <ssb@php.net>
Thu, 9 Jan 2003 15:14:23 +0000 (15:14 +0000)
pear/PEAR.php

index 7fa35a8495d4dadb3157bc3d87328322d925ba07..7f034b7b0a9952e535e92acc1409a54f0cbdaeda 100644 (file)
@@ -670,11 +670,7 @@ class PEAR_Error
     var $code                 = -1;
     var $message              = '';
     var $userinfo             = '';
-
-    // Wait until we have a stack-groping function in PHP.
-    //var $file    = '';
-    //var $line    = 0;
-
+    var $backtrace            = null;
 
     // }}}
     // {{{ constructor
@@ -709,6 +705,9 @@ class PEAR_Error
         $this->code      = $code;
         $this->mode      = $mode;
         $this->userinfo  = $userinfo;
+        if (function_exists("debug_backtrace")) {
+            $this->backtrace = debug_backtrace();
+        }
         if ($mode & PEAR_ERROR_CALLBACK) {
             $this->level = E_USER_NOTICE;
             $this->callback = $options;
@@ -853,6 +852,25 @@ class PEAR_Error
         return $this->getUserInfo();
     }
 
+    // }}}
+    // {{{ getBacktrace()
+
+    /**
+     * Get the call backtrace from where the error was generated.
+     * Supported with PHP 4.3.0 or newer.
+     *
+     * @param int $frame (optional) what frame to fetch
+     * @return array Backtrace, or NULL if not available.
+     * @access public
+     */
+    function getBacktrace($frame = null)
+    {
+        if ($frame === null) {
+            return $this->backtrace;
+        }
+        return $this->backtrace[$frame];
+    }
+
     // }}}
     // {{{ addUserInfo()