php - static variable not incrementing on function calling -
function gentokenno() { static $i=0; $i=$i+1; return str_pad($i, 5, '0', str_pad_left); }
when calls function in other file function doesn't returns unique value (an incremented value). while echo function in same file(where function made) works fine. know concept of scope of static variable have tried replacing $i $_session['i'] no expected result. in advance.
note value of $i
not persisted. whenever run new request server, script reloaded , $i
reset 0
.
to persist variable in per-user session use $session['i']
tried, unique per session, not globally.
to have globally unique number need store on disk, using fopen
/flock
/fread
/fwrite
/fclose
functions.
Comments
Post a Comment