PHP中的调试变量的范围

I am aware of all the great debug engines out there like Zend or xdebug, but I just want a simple error_log("Something"); debug mode.

I have a class like this:

class myClass {

    $DEBUG_MODE = True;

    public function someFunction(){

        if($DEBUG_MODE)
        {
            error_log($varName); // outputs to my Apache server's error log file.
        }
    }
}

However, I get the below error:

Undefined variable: DEBUG_MODE in path in line: integer

I am probably mixing up my Java and PHP... Could someone give me some insight or perhaps a better way to debug?

You should access class properties somehow (either statically or by object). My answer shows how to do it statically (so every object of myClass can use the same value):

<?php

class myClass {

    // make it static so you don't have to set it in every instance of myClass
    protected static $DEBUG_MODE = True;

    public function someFunction(){

        if(self::$DEBUG_MODE) // reference the static variable from this class
        {
            error_log($varName); // outputs to my Apache server's error log file.
        }
    }
}

To access class properties (and methods), you should use $this->

if ($this->DEBUG_MODE)

Notice that there is no $ behind DEBUG_MODE

try like this :

class myClass {

    private $DEBUG_MODE = True;

    public function someFunction(){

        if($this->DEBUG_MODE)
        {
            error_log($varName); // outputs to my Apache server's error log file.
        }
    }
}

and for logging you can use apache log4php

if you want debug your php code inline ! simply use php vardump function

it's very good tools for debugging and get variable value

var_dump($varName);