Print the variable name and the varable content

PHOTO EMBED

Tue Feb 02 2021 15:33:48 GMT+0000 (UTC)

Saved by @GoodGabriel #php

function getVarName(){

  //  https://github.com/gaffling/PHP-Get-Variable-Name-as-a-String/blob/master/function.php
  //  echo get_var_name($FooBar).' - '.$FooBar;

    // read backtrace
    $bt   = debug_backtrace();
    // read file
    $file = file($bt[0]['file']);
    // select exact print_var_name($varname) line
    $src  = $file[$bt[0]['line']-1];
    // search pattern
    $pat = '#(.*)'.__FUNCTION__.' *?\( *?(.*) *?\)(.*)#i';
    // extract $varname from match no 2
    $var  = preg_replace($pat, '$2', $src);
    // return the var name
    return trim($var);
}


function debugServer($input, $input_name = "")
{
    $temp = print_r($input, true);
    
    error_log(  $input_name . " : "  . $temp);
}
content_copyCOPY