note 100350 modified in function.debug-backtrace by danbrown
| From: | danbrown@php.net | Date: | Sun, 10 Oct 2010 15:35:16 +0000 |
| Subject: | note 100350 modified in function.debug-backtrace by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173113@lists.php.net to get a copy of this message | ||
I find it useful to know if a function is being called. in Java for instance you usually print a
line with the functionname and arguments in the beginning of the function. I wanted to achieve the
same thing in php thus i wrote the following class:
<?php
class Debug
{
private static $calls;
public static function log($message = null)
{
if(!is_array(self::$calls))
self::$calls = array();
$call = debug_backtrace(false);
$call = (isset($call[1]))?$call[1]:$call[0];
$call['message'] = $message;
array_push(self::$calls, $call);
}
}
?>
include this class before anything else
usage: Debug::log($message); at the beginning of your function.
write yourself a nice printout of the data;
--was--
I find it useful to know if a function is being called. in Java for instance you usually print a
line with the functionname and arguments in the beginning of the function. I wanted to achieve the
same thing in php thus i wrote the following class:
class Debug
{
private static $calls;
public static function log($message = null)
{
if(!is_array(self::$calls))
self::$calls = array();
$call = debug_backtrace(false);
$call = (isset($call[1]))?$call[1]:$call[0];
$call['message'] = $message;
array_push(self::$calls, $call);
}
}
include this class before anything else
usage: Debug::log($message); at the beginning of your function.
write yourself a nice printout of the data;
http://php.net/manual/en/function.debug-backtrace.php