public function testRecursionMaxDepth()
 {
     $serializer = new Raven_ReprSerializer();
     $input = array();
     $input[] =& $input;
     $result = $serializer->serialize($input, 3);
     $this->assertEquals(array(array(array('Array of length 1'))), $result);
 }
 public static function get_stack_info($frames, $trace = false, $shiftvars = true, $errcontext = null, $frame_var_limit = Raven_Client::MESSAGE_LIMIT, $strip_prefixes = null, $app_path = null)
 {
     /**
      * PHP's way of storing backstacks seems bass-ackwards to me
      * 'function' is not the function you're in; it's any function being
      * called, so we have to shift 'function' down by 1. Ugh.
      */
     $result = array();
     for ($i = 0; $i < count($frames); $i++) {
         $frame = $frames[$i];
         $nextframe = isset($frames[$i + 1]) ? $frames[$i + 1] : null;
         if (!array_key_exists('file', $frame)) {
             // XXX: Disable capturing of anonymous functions until we can implement a better grouping mechanism.
             // In our examples these generally didn't help with debugging as the information was found elsewhere
             // within the exception or the stacktrace
             continue;
             // if (isset($frame['args'])) {
             //     $args = is_string($frame['args']) ? $frame['args'] : @json_encode($frame['args']);
             // }
             // else {
             //     $args = array();
             // }
             // if (!empty($nextframe['class'])) {
             //     $context['line'] = sprintf('%s%s%s(%s)',
             //         $nextframe['class'], $nextframe['type'], $nextframe['function'],
             //         $args);
             // }
             // else {
             //     $context['line'] = sprintf('%s(%s)', $nextframe['function'], $args);
             // }
             // $abs_path = '';
             // $context['prefix'] = '';
             // $context['suffix'] = '';
             // $context['filename'] = $filename = '[Anonymous function]';
             // $context['lineno'] = 0;
         } else {
             $context = self::read_source_file($frame['file'], $frame['line']);
             $abs_path = $frame['file'];
         }
         // strip base path if present
         $context['filename'] = self::strip_prefixes($context['filename'], $strip_prefixes);
         $module = basename($abs_path);
         if (isset($nextframe['class'])) {
             $module .= ':' . $nextframe['class'];
         }
         if (empty($result) && isset($errcontext)) {
             // If we've been given an error context that can be used as the vars for the first frame.
             $vars = $errcontext;
         } else {
             if ($trace) {
                 if ($shiftvars) {
                     $vars = self::get_frame_context($nextframe, $frame_var_limit);
                 } else {
                     $vars = self::get_caller_frame_context($frame);
                 }
             } else {
                 $vars = array();
             }
         }
         $data = array('filename' => $context['filename'], 'lineno' => (int) $context['lineno'], 'module' => $module, 'function' => $nextframe['function'], 'pre_context' => $context['prefix'], 'context_line' => $context['line'], 'post_context' => $context['suffix']);
         // detect in_app based on app path
         if ($app_path) {
             $data['in_app'] = (bool) (substr($abs_path, 0, strlen($app_path)) === $app_path);
         }
         // dont set this as an empty array as PHP will treat it as a numeric array
         // instead of a mapping which goes against the defined Sentry spec
         if (!empty($vars)) {
             $serializer = new Raven_ReprSerializer();
             $cleanVars = array();
             foreach ($vars as $key => $value) {
                 $value = $serializer->serialize($value);
                 if (is_string($value) || is_numeric($value)) {
                     $cleanVars[$key] = substr($value, 0, $frame_var_limit);
                 } else {
                     $cleanVars[$key] = $value;
                 }
             }
             $data['vars'] = $cleanVars;
         }
         $result[] = $data;
     }
     return array_reverse($result);
 }