note 104908 added to function.func-get-args

From: Date: Fri, 15 Jul 2011 02:11:11 +0000
Subject: note 104908 added to function.func-get-args
Groups: php.notes 
Request: Send a blank email to php-notes+get-181541@lists.php.net to get a copy of this message
I slightly improved version of the previous poster's awesome function. <?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=true) { $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"; //var_dump($v); //[dv] I discovered a bug in PHP 5.3.6 where is_string() and is_null() are reversed in case statements?! // Therefore I had to split these off to if/else until it's fixed. :-\ if (is_string($v)) { if ($show_empty_params) $v = "'".$v."'"; } elseif (is_null($v)) { if ($show_empty_params) $v = '{NULL}'; } else switch($v) { //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 "params[$k] = ".$params[$k]."<br>\n"; } 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/104908 Del: integrated -- https://master.php.net/note/delete/104908/integrated Del: useless -- https://master.php.net/note/delete/104908/useless Del: bad code -- https://master.php.net/note/delete/104908/bad+code Del: spam -- https://master.php.net/note/delete/104908/spam Del: non-english -- https://master.php.net/note/delete/104908/non-english Del: in docs -- https://master.php.net/note/delete/104908/in+docs Del: other reasons-- https://master.php.net/note/delete/104908 Reject -- https://master.php.net/note/reject/104908 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#181541) next »