note 111255 added to function.debug-backtrace

From: Date: Wed, 30 Jan 2013 20:12:51 +0000
Subject: note 111255 added to function.debug-backtrace
Groups: php.notes 
Request: Send a blank email to php-notes+get-193449@lists.php.net to get a copy of this message
Simple function to get a string in form "filename: [class->][function(): ]" <?php function get_caller_info() { $c = ''; $file = ''; $func = ''; $class = ''; $trace = debug_backtrace(); if (isset($trace[2])) { $file = $trace[1]['file']; $func = $trace[2]['function']; if ((substr($func, 0, 7) == 'include') || (substr($func, 0, 7) == 'require')) { $func = ''; } } else if (isset($trace[1])) { $file = $trace[1]['file']; $func = ''; } if (isset($trace[3]['class'])) { $class = $trace[3]['class']; $func = $trace[3]['function']; $file = $trace[2]['file']; } else if (isset($trace[2]['class'])) { $class = $trace[2]['class']; $func = $trace[2]['function']; $file = $trace[1]['file']; } if ($file != '') $file = basename($file); $c = $file . ": "; $c .= ($class != '') ? ":" . $class . "->" : ""; $c .= ($func != '') ? $func . "(): " : ""; return($c); } ?> Usage like: <?php function debug($str) { echo get_caller_info() . $str . "<br>\n"; } ?> get_caller_info() will return info about the function /class->method that called debug(). ---- Server IP: 69.147.83.199 Probable Submitter: 194.136.233.81 ---- Manual Page -- http://php.net/manual/en/function.debug-backtrace.php Edit -- https://master.php.net/note/edit/111255 Del: integrated -- https://master.php.net/note/delete/111255/integrated Del: useless -- https://master.php.net/note/delete/111255/useless Del: bad code -- https://master.php.net/note/delete/111255/bad+code Del: spam -- https://master.php.net/note/delete/111255/spam Del: non-english -- https://master.php.net/note/delete/111255/non-english Del: in docs -- https://master.php.net/note/delete/111255/in+docs Del: other reasons-- https://master.php.net/note/delete/111255 Reject -- https://master.php.net/note/reject/111255 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#193449) next »