[pmwiki-users] best practice

Joachim Durchholz jo at durchholz.org
Tue May 9 12:28:51 CDT 2006

Crisses schrieb:
> You can probably use a static variable.

It won't live across invocations of PmWiki.

A session variable won't cut it either, because the counter must retain 
its value across sessions. (That is, it must be the same counter for 
visitors A and B which happen to visit the site at the same time, and it 
must survive even after the session has expired.)

> You can increment a static variable as a counter, and it will  
> remember its value between iterations of the php program.

That's definitely WRONG. No such beast exists inside PHP.

> function Test()
> {
>     static $a = 0;
>     echo $a;
>     $a++;
> }
> Now, every time the Test() function is called it will print the value  
> of $a and increment it.

Ah, now I see where the mixup came from. This description is incomplete.

$a will retain its value between invocations of Test() all right, but 
*not from one script invocations to the next* (that is, not from one run 
of pmwiki.php to the next).

> I don't know a lot about it, but from what I do know, these variables  
> can be used for web page counters,

I'd be *very* suprised if that indeed worked. Web page counters usually 
store their value somewhere external to PHP, e.g. in a file or in a 
database record.


More information about the pmwiki-users mailing list