View Single Post
  #3  
Old 05-04-2009, 04:42 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Quote:
Originally Posted by Loriel View Post
TStaticVar :|
Not exactly what I meant. I meant like the way the static keyword works in C functions. As you probably know, so that variables retain their values even after the function's end, but can't be accessed script-wide, just in that function.

For example:

PHP Code:
function onCreated() {
 for (
temp.0temp.10temp.i++) {
  echo(
staticTest());
 }
}

function 
staticTest() {
  if (
temp.staticVar == NULLtemp.staticVar = new TStaticVar();
  
temp.staticVar.var1++;
  return 
temp.staticVar.var1;

outputs this:

PHP Code:
1
1
1
1
1
1
1
1
1

Reply With Quote