/
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 called like "
$this->Application->isDebugMode();
" checks that debug mode enabled AND no active IDE debug session (e.g. https://confluence.jetbrains.com/display/PhpStorm/Using+the+PhpStorm+Debugger) is in effect - when called like "
$this->Application->isDebugMode(false);
" checks that debug mode enabled
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 Construct | Description | Pros | Cons |
---|---|---|---|
defined('DEBUG_MODE') && DEBUG_MODE |
|
| |
$this->Application->isDebugMode(); |
|
|
|
$this->Application->isDebugMode(false); |
|
|
|
defined('DEBUG_MODE') && DEBUG_MODE && $this->Application->isDebugMode(); |
|
|
Solution
- locate all checks for debug mode
- decide which of above described code samples needs to be used in each case
- 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)