note 104923 added to function.func-get-args

From: Date: Fri, 15 Jul 2011 17:44:55 +0000
Subject: note 104923 added to function.func-get-args
Groups: php.notes 
Request: Send a blank email to php-notes+get-181578@lists.php.net to get a copy of this message
An updated version of the awesome function below... <?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"; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 207.178.4.251 ---- Manual Page -- http://www.php.net/manual/en/function.func-get-args.php Edit -- https://master.php.net/note/edit/104923 Del: integrated -- https://master.php.net/note/delete/104923/integrated Del: useless -- https://master.php.net/note/delete/104923/useless Del: bad code -- https://master.php.net/note/delete/104923/bad+code Del: spam -- https://master.php.net/note/delete/104923/spam Del: non-english -- https://master.php.net/note/delete/104923/non-english Del: in docs -- https://master.php.net/note/delete/104923/in+docs Del: other reasons-- https://master.php.net/note/delete/104923 Reject -- https://master.php.net/note/reject/104923 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#181578) next »