Hi,
I'm trying to create a Debugging static class that is compatible with PHP4 but I'm having a great degree of difficulty trying to understand how PHP4 handles static variables. Currently, I have several internal functions that access and assign values to a static array i've declared inside my Debugging class like so:
class Debugger
{
static $DebugClassVariables = array();
function register($name)
{
$newVariable = '';
static $DebugClassVariables;
if (!is_array($DebugClassVariables))
$DebugClassVariables = array();
$DebugClassVariables[$name] = $newVariable;
}
function set($name, $value)
{
static $DebugClassVariables;
if (!is_array($DebugClassVariables))
$DebugClassVariables = array();
$DebugClassVariables[$name] = $value;
}
}
I have a function called initialize() that performs all the needed register() and set() calls:
function initialize()
{
Debugger::register('DebugArray');
Debugger::register('Symbols');
Debugger::register('IndentSymbols');
Debugger::register('UnIndentSymbols');
Debugger::register('CurrentIndent');
Debugger::register('IndentPerSymbol');
Debugger::register('Indent');
Debugger::set('Indent', ' ');
Debugger::set('IndentPerSymbol', 4);
Debugger::set('CurrentIndent', 0);
}
Now here is the behavior that i'm not understanding; Successive calls to the register function result in these respective values for the $DebugVariablesArray:
Array ( [DebugArray] => Array ( ) )
Array ( [DebugArray] => Array ( ) [Symbols] => Array ( ) )
Array ( [DebugArray] => Array ( ) [Symbols] => Array ( ) [IndentSymbols] => Array ( ) )
Array ( [DebugArray] => Array ( ) [Symbols] => Array ( ) [IndentSymbols] => Array ( ) [UnIndentSymbols] => Array ( ) )
Array ( [DebugArray] => Array ( ) [Symbols] => Array ( ) [IndentSymbols] => Array ( ) [UnIndentSymbols] => Array ( ) [CurrentIndent] => )
Array ( [DebugArray] => Array ( ) [Symbols] => Array ( ) [IndentSymbols] => Array ( ) [UnIndentSymbols] => Array ( ) [CurrentIndent] => [IndentPerSymbol] => )
Array ( [DebugArray] => Array ( ) [Symbols] => Array ( ) [IndentSymbols] => Array ( ) [UnIndentSymbols] => Array ( ) [CurrentIndent] => [IndentPerSymbol] => [Indent] => )
Which Makes sense. But this is what happens to the $DebugVariablesArray whenever the three calls to the set() function are made:
Array ( [Indent] => )
Array ( [Indent] => [IndentPerSymbol] => 4 )
Array ( [Indent] => [IndentPerSymbol] => 4 [CurrentIndent] => 0 )
Functions called after this point that attempt to modify or use the $DebugVariablesArray can't find it at all - calling var_dump() on it just print NULL. I can't seem to figure out what's going on here. Any assistance?