note 104910 deleted from function.func-get-args by danbrown
| From: | danbrown@php.net | Date: | Fri, 15 Jul 2011 14:22:09 +0000 |
| Subject: | note 104910 deleted from function.func-get-args by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-181567@lists.php.net to get a copy of this message | ||
Note Submitter: daevid at daevid dot com
----
Upgraded version of the awesome function the fellow below started...
<?php
/**
* Useful for debugging functions to see parameter names, etc.
* Based upon http://www.php.net/manual/en/function.func-get-args.php#103296
*
* function anyfunc($arg1, $arg2, $arg3)
* {
* debug_func(__FUNCTION__, '$arg1, $arg2, $arg3', func_get_args());
* //do useful non-debugging stuff
* }
*
* @access public
* @return string
* @param string $function_name __FUNCTION__ of the root function as passed into this function
* @param string $arg_names the ',,,' encapsulated parameter list of the root function
* @param array $arg_vals the result of func_get_args() from the root function passed into this
function
* @param boolean $show_empty_params (FALSE)
* @author Daevid Vincent
* @date 2011-17-14
* @see func_get_args(), func_get_arg(), func_num_args()
*/
function debug_func($function_name, $arg_names, $arg_vals, $show_empty_params=FALSE)
{
$params = array();
echo $function_name.'(';
$arg_names_array = explode(',', $arg_names);
//var_dump($arg_names, $arg_names_array, $arg_vals );
foreach($arg_names_array as $k => $parameter_name)
{
$v = $arg_vals[$k];
//echo "k = $parameter_name = $k and v = arg_vals[k] = $v<br>\n";
switch(true)
{
case is_string($v): if ($show_empty_params) $v = "'".$v."'" ;
break;
case is_null($v): if ($show_empty_params) $v = '{NULL}'; break;
case is_bool($v): $v = ($v) ? '{TRUE}' : '{FALSE}'; break;
case is_array($v): (count($v) < 10) ? $v =
'['.implode(',',$v).']' : $v = '[ARRAY]'; break;
case is_object($v): $v = '{CLASS::'.get_class($v).'}'; break;
case is_numeric($v): break;
}
if ($show_empty_params || $v) $params[$k] = trim($parameter_name).': '.$v;
}
echo implode(', ',$params).")<br/>\n";
}
?>