php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #40918 Enhance debug_backtrace to supply the name of parameters.
Submitted: 2007-03-26 09:35 UTC Modified: 2010-12-22 13:27 UTC
From: RQuadling@php.net Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 4.4.5 OS: n/a
Private report: No CVE-ID: None
 [2007-03-26 09:35 UTC] RQuadling@php.net
Description:
------------
Currently, debug_backtrace() supplies details of parameters to the function/method calls in the current call stack. This is extremely useful for debugging.

I feel that this could be enhanced by adding the name of the parameters passed to a function/method.

Currently I have to read the file associated with the function and then regexp the line to extract the parameters. This is getting more and more complicated trying to support different users coding practices.

I've supplied an contrived example with the expected output for the new functionality.

I initially thought that the keys of the 'args' array could be the parameters, but this would be a BC as currently they are numeric, so a new array of 'params' (Hmmm - not a great name - would need a better one), could hold the parameter text. If the parameter is a function call, then the param value would be the function call with its parameters.

The main purpose is that you can show the actual parameter names the code is using in addition to the the values.


Reproduce code:
---------------
<?php
function func($m_Param1, $m_Param2)
	{
	var_export(debug_backtrace());
	return True;
	}

$s_Foo = 'Foo';
$s_Bar = 'Bar';
func($s_Foo, $s_Bar, func($s_Foo, $s_Bar));
?>

Expected result:
----------------
array (
  0 =>
  array (
    'file' => 'C:\\va.php',
    'line' => 10,
    'function' => 'func',
    'args' =>
    array (
      0 => 'Foo',
      1 => 'Bar',
    ),
    'params' =>
    array (
      0 => '$s_Foo',
      1 => '$s_Bar',
    ),
  ),
)array (
  0 =>
  array (
    'file' => 'C:\\va.php',
    'line' => 10,
    'function' => 'func',
    'args' =>
    array (
      0 => 'Foo',
      1 => 'Bar',
      2 => true,
    ),
    'params' =>
    array (
      0 => '$s_Foo',
      1 => '$s_Bar',
      2 => 'func($s_Foo, $s_Bar)',
    ),
  ),
)

Actual result:
--------------
array (
  0 =>
  array (
    'file' => 'C:\\va.php',
    'line' => 10,
    'function' => 'func',
    'args' =>
    array (
      0 => 'Foo',
      1 => 'Bar',
    ),
  ),
)array (
  0 =>
  array (
    'file' => 'C:\\va.php',
    'line' => 10,
    'function' => 'func',
    'args' =>
    array (
      0 => 'Foo',
      1 => 'Bar',
      2 => true,
    ),
  ),
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-22 13:27 UTC] johannes@php.net
-Status: Open +Status: Bogus -Package: Feature/Change Request +Package: *General Issues
 [2010-12-22 13:27 UTC] johannes@php.net
You can easily grab the parameters using reflection nowadays. Doing this automatically is relatively expensive and won't work always (varargs)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 11:01:37 2024 UTC