Toggling debug output within a PHP class

I don’t care what anyone says, I like lots of debug output available in my programs. It helps me crank out code faster with less errors. You can keep a private member called debug and just flip it on and off when you want to see the output. It’s a lot cleaner than interjecting prints and echos all over the place.

php-logo-125x125

<?php
class SomeObject {
    private $debug = true;
    private $var;

    public function __construct($incoming) {
        if ($this->debug)
            echo "var=[".$var."]<br>";
    }

    public function getvar() {
        return $this->var;
    }

    public function setvar($var) {
        if ($this->var = $var)
            return true;
        else
            return false;
    }
}

Adding a public setDebug function lets you turn the output on and off outside the class too.

public function setDebug($bool) {
    $this->debug = $bool;
}

I know… such an amateur!

Posted by admica   @   6 August 2009
Tags : , , , , , ,

Related Posts

0 Comments

No comments yet. Be the first to leave a comment !
Leave a Comment

Name

Email

Website

Previous Post
« How to pass multiple post array variables in PHP
Next Post
Wordpress Automatic Updates broken, asks for Connection Information - fixed! »
Powered by Wordpress   |   Lunated designed by ZenVerse