Skip to content

Instantly share code, notes, and snippets.

@cakyus
Created October 16, 2012 12:59
Show Gist options
  • Select an option

  • Save cakyus/3899122 to your computer and use it in GitHub Desktop.

Select an option

Save cakyus/3899122 to your computer and use it in GitHub Desktop.
Example of Static Variable
class classA {
function functionA() {
static $variableA;
if (is_null($variableA)) {
$variableA = 0;
} else {
$variableA++;
}
return $variableA;
}
}
$a = new classA;
echo $a->functionA(); // 0
echo $a->functionA(); // 1
$a = new classA;
echo $a->functionA(); // 2
echo $a->functionA(); // 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment