Creating simple debug-tool with php

Jussi Pohjolainen

Tampere University of Applied Sciences » Computer Science

Intro to debug

Creating simple debug-tool

Setting global debug-variable

Example

require_once("conf/conf.php");
function myFunction ($input)
{
    global $DEBUG;
    if($DEBUG)
    {
        print "Input: [$input]";
    }
    // Some logic here
    $ret = $input*2;
    if($DEBUG)
    {
        print "Return: [$ret]";
    }
    return $ret;
}

Setting ID

Creating debug-function

Debug Levels

Creating Debug-class

class Debug
{
    private $className;
    public function __construct ( $className )
    {
        $this->className = $className;
    }
    public function debug ($functionName, $message, $level = 1) { ... }
}

class Math extends Debug
{
    public function __construct ()   // PHP5
    {
        parent::__construct("Math");
    }
}