/
Inconsistent debug mode checking code [5.2.2-B1]

Inconsistent debug mode checking code [5.2.2-B1]

The Debug Mode is special mode of In-Portal operation, where additional debugging information (e.g. what database queries are executed) is collected and displayed back to developer. For a developer to be in a Debug Mode all of following must be true:

  • the "/system/debug.php" file is present
  • inside "/system/debug.php" the "DEBUG_MODE" setting is enabled
  • the developer IP address must be listed in "DBG_IP" setting inside "/system/debug.php" file
  • the "debug_off" cookie must not be set

There is also "kApplication::isDebugMode" method is designed to check 2 things:

When active IDE debug session is present, then In-Portal debugger automatically turns itself off, because IDE would provide same information anyway. In some cases however we need to know if debug mode would have been enabled, when there is no IDE debug session. That's where later call to "isDebugMode" mode is used.

To summarize there are following constructs used for Debug Mode detection:

Code ConstructDescriptionProsCons
defined('DEBUG_MODE') && DEBUG_MODE
  • checks if Debug Mode is enabled ignoring active IDE debugging session check
  • equivalent to "$this->Application->isDebugMode(false);" code
  • no method call is made, which is better when doing lots of debug mode checks in a row (e.g. cycle)
 
$this->Application->isDebugMode();
  • checks if Debug Mode is enabled honoring active IDE debugging session check
  • dedicated method usage
  • extra method call
$this->Application->isDebugMode(false);
  • checks if Debug Mode is enabled ignoring active IDE debugging session check
  • dedicated method usage
  • extra method call
defined('DEBUG_MODE') && DEBUG_MODE && $this->Application->isDebugMode();
  • only when debug mode is enabled in call method to confirm absense of active IDE debug session
  • best of both worlds
 

Solution

  1. locate all checks for debug mode
  2. decide which of above described code samples needs to be used in each case
  3. optimize "kApplication::isDebugMode" in a way, that debug mode flag would be store as static variable in the method (because debug mode can't be disabled during script run)

Related Tasks