Menu

#9 Krumo CAN show the name of the passed variable

open
nobody
None
5
2007-07-20
2007-07-20
Jawad
No

With this little piece of code found on http://fr3.php.net/manual/en/language.variables.php :
function var_name(&$var, $scope=0)
{
$old = $var;
if (($key = array_search($var = 'unique'.rand().'value', !$scope ? $GLOBALS : $scope)) && $var = $old) return $key;
}

I would be happy to help in Krumo's development if you need help.

Jawad

Discussion

  • Nobody/Anonymous

    Logged In: NO

    I made a simply modification, so a description to the variable is shown.

    In class.krumo.php I changed:
    1. Function dump($data, $name = '...')

    2. (about line 580)
    <div class="krumo-root">
    <ul class="krumo-node krumo-first">
    <?php echo krumo::_dump($data, $name);?>

    Now I call: krumo( $variable, 'variable' );

    I think, this solution will have some side effects. But If you are only using the call above, it should work. Nethertheless the idea is a good starting-point for easily extend krumo.

     
  • Nobody/Anonymous

    Logged In: NO

    wow - i never knew that. cool.

     
  • pir

    pir - 2011-09-19

    I had an other idea:
    You know the file, you know the line, let's grep out the krumo call of the php file.

    $varname=exec('sed -n -r \''.$d['line'].' s/.+krumo\((\$.+)\);/\1/ p\' '.$d['file']);

    For less precision, we could just print the calling line, and it could be done more simply with sed, awk, head | tail, grep, ...

    Cons:
    * need to be sure to have sed and of the options to send to sed (mine is GNU sed version 4.2.1)
    * krumo function must not be renamed (or you must know the name and adapt the call)
    * will write all the args for each box if krumo has been called with 2 vars. krumo($var1, $var2)
    * will only write the last call if krumo has been called twice, once per var. krumo($var1); krumo($var2);

     
  • h@rl0cK76

    h@rl0cK76 - 2011-09-29

    Hi guys,
    I made a similar workaround too. You can find it here
    https://sourceforge.net/tracker/?func=detail&aid=3022585&group_id=194198&atid=948468
    (there's a ready modified class)

    Basically it's the same idea issued by ppir .
    However I'm using it since last year and I did't notice any side effect.

    I'm curios to hear what do you think about it.
    cheers,
    G

     
  • pir

    pir - 2011-11-08

    I just benchmarked with your file and mine.

    My current technique is $varname=exec("sed -n '$d[line] p' $d[file]");
    For 1000 krumo calls, my file takes 3 s.
    With your file, it takes 68 ms.

    So exec(sed) is not performant at all (i could have guessed it).

     

Log in to post a comment.

MongoDB Logo MongoDB