Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions

Reply
 
Thread Tools Display Modes
  #11  
Old 05-28-2002, 08:10 PM
Jawelin Jawelin is offline
 
Join Date: Nov 2001
Posts: 557
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #12  
Old 05-29-2002, 08:27 AM
Logician's Avatar
Logician Logician is offline
 
Join Date: Nov 2001
Location: inside vb code
Posts: 4,449
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #13  
Old 05-29-2002, 09:44 AM
Jawelin Jawelin is offline
 
Join Date: Nov 2001
Posts: 557
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by Logician
ok let me summarize:
[...]
Hope this helps..
Logician
Wow!!! What a lesson!
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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:59 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03709 seconds
  • Memory Usage 2,182KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (3)post_thanks_box
  • (3)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit_info
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete