Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /******
- - We use constants like PI, do not expect to ever need to change during the program's run.
- - Static variables are, in fact, variable. The "static" means that the variable retains its value between calls to whatever that variable's scope is (function, class, procedure, etc.). PHP only supports static variables within the scope of a function definition.
- http://www.webdeveloper.com/forum/showthread.php?67283-how-to-declare-static-variable-in-php
- *******/
- //static vs non static variables
- function incrementStatic()
- {
- static $myVar = 0;
- $myVar++;
- return($myVar);
- }
- echo "Static : <pre>";
- echo incrementStatic() . "\n";
- echo incrementStatic() . "\n";
- echo incrementStatic() . "\n";
- function incrementNormal()
- {
- $myVar = 0;
- $myVar++;
- return($myVar);
- }
- echo "\nNormal <pre>";
- echo incrementNormal() . "\n";
- echo incrementNormal() . "\n";
- echo incrementNormal() . "\n";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement