The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#11
|
|||
|
|||
Thank you very much for this example of session. I didn't understand too much from php.net...
Btw, I would investigate better the way of static var: if I call a function within a script, and in that function I had such a static var, that var will become available (and maintain the same value) for all the script execution time, is it true ? No matter if other scripts call the same function... they are different scripts, so that var will not keep the same value of the first script... Is it true ? Thanks again, foa for all the time you're spending with me... Thank you. |
#12
|
||||
|
||||
ok let me summarize:
1- First thing to learn about PHP scripts is that: every script run is independent from others. This means that when I visit a thread here, "showthread.php" runs for ME and if you at the same time visit the same or an other thread same script will run for you TOO, but this running will be completely different from my running. (even if we click showthread.php just at the same EXACT second) Say, if my running the script change the variable of $a from 1 to 2, even if you run the script at the same time, $a variable would be "1" for you UNLESS your running changed its value for YOU too.. In other words everytime user A run a script, script will begin from the begining with default variable values. Others running of the scripts for other users would not effect variable values for user A. 2- Every run of the script (whether from the same user or not) is independent from eachother too. So if I run showthread.php to visit a thread, then click to an other thread in 2 seconds, another run of showthread.php will begin for me! They are not same so the variables will be reset again even if I'm the same user running the same script. That's why you use session variables, they keep their values after script is ended, until I close my session in your site and if I run the same script in the same session, session variables will keep their values.. 2- If a PHP script is not "included" or "required" inside another PHP script, these are completely different scripts and running of one does not effect other (applies to variables too). So for example if you assigned: $a=1; in global.php, $a would be 0 in showthread.php. It keeps its value in showthread.php too, JUST BECAUSE in the begining of that file global.php is "included". (So they become "one script"). Delete this line from showthread.php and you'll lose all variable values assigned in global.php... 3- GLOBAL usage in functions: $a = 1; function Test() { echo $a;} Test(); will print nothing. Because $a is a global (outside function)variable and $a in the function is different from $a outside the function.. $a = 1; function Test() { global $a; echo $a;} Test(); will print 1, because you now told your function to use global $a outside the function inside the function too.. 4- STATIC usage: Everytime a function runs, its variables (which is not "global"ized) get reset. Static helps to preserve their value inside the function, if the function is run again (inside the same script running! if same or another user runs the script again, variables reset remember?) function Test() { $b++;echo $b;} test() it will print 1 whenever you call the function test function Test() { static $b=0; $b++} Test(); it will print 1,2,3,4,5.. whenever you call the function test. Because static keeps the value of $b after function ends.. Hope this helps.. Logician |
#13
|
|||
|
|||
Quote:
I'm gonna studying... Thanks a lot! Always look for a similar basic tutorial... Now I'll try to apply and later will let you know. Thanks again. Bye |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|