I want to check if a static variable has been declared/initialized previously, e.g. if a function with a static variable is being run for the first time. See the following example code:
function init_i (){
// check if $i is set??
if(isset($i)) echo '$i is static and is set ';
static $i=0;
$i++;
echo "$i<br>";
}
function run_init(){
init_i();
}
run_init(); //output 1
run_init(); //should output $i is static and is set 2
run_init(); //should output $i is static and is set 3
run_init(); //should output $i is static and is set 4
run_init(); //should output $i is static and is set 5
The problem is that isset($i) never seems to prove true even though it is a static variable. How do I check static $i has already been set?