Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #11  
Old 10-26-2004, 11:35 AM
Ocean's Avatar
Ocean Ocean is offline
 
Join Date: Mar 2004
Posts: 208
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Colin F

I'm not sure what you mean by "only at that moment".
The data is saved in the variable and this is usable like any other variable.
I thought "echo" was an immediate output function - so that if you ran the following...

PHP Code:
 
<?
 
$i = 10;
 
echo ($i);
 
?>

...you would have "10" displayed on screen.

Was I mistaken?
Reply With Quote
  #12  
Old 10-26-2004, 12:28 PM
Colin F's Avatar
Colin F Colin F is offline
 
Join Date: Jul 2004
Location: Switzerland
Posts: 1,551
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Ocean
I thought "echo" was an immediate output function - so that if you ran the following...

PHP Code:
 
<?
 
$i = 10;
 
echo ($i);
 
?>

...you would have "10" displayed on screen.

Was I mistaken?
Oh of course

I just wrote the echo line to show that the variable can be used normally. You don't have to echo it, you can use it like any other variable.
Reply With Quote
  #13  
Old 10-26-2004, 04:51 PM
Ocean's Avatar
Ocean Ocean is offline
 
Join Date: Mar 2004
Posts: 208
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Colin F

Oh of course

I just wrote the echo line to show that the variable can be used normally. You don't have to echo it, you can use it like any other variable.
My mistake.


Well, that being the case - I'm still curious - is there any difference in function or performance between returning the values or globalising the variables? Or are there no significant differences or merits to using one as opposed to the other?
Reply With Quote
  #14  
Old 10-26-2004, 09:56 PM
Natch's Avatar
Natch Natch is offline
 
Join Date: Nov 2002
Location: Australia
Posts: 851
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Globalising a variable is useful IMO when you have a lot of data you wanna pass back in many different variables, whereas a small function for a sepcific purpose might just return one value or array, in which case returning the variable and keeping it out of the $GLOBALS array may be more suitable.

Two examples:

- passing a number to a function to return a ordinalised string (1, 2, 3 => 1st, 2nd, 3rd) would be better simply to have
PHP Code:
$parsed_string ordinalise($number); 
and
PHP Code:
function ordinalize($num
{
    if (!
is_numeric($num))
        return 
$num;

    if (
$num >= 11 and $num <= 19) return $num."th";
    elseif ( 
$num 10 == ) return $num."st";
    elseif ( 
$num 10 == ) return $num."nd";
    elseif ( 
$num 10 == ) return $num."rd";
    else return 
$num."th";

NOTE: I know this could be switched, but this is just an example)

- If you are trying to test for or generate a data caches, you might be better off globalising them at the start of the function, then you wont have to create a multi-dimensional array of the values you want to return, then
PHP Code:
list($cacheone$cachetwo$cache_three) = caching_function(); 
afterwards...

I hope that makes sense?
Reply With Quote
  #15  
Old 10-27-2004, 02:01 AM
Ocean's Avatar
Ocean Ocean is offline
 
Join Date: Mar 2004
Posts: 208
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Natch

Globalising a variable is useful IMO when you have a lot of data you wanna pass back in many different variables, whereas a small function for a sepcific purpose might just return one value or array, in which case returning the variable and keeping it out of the $GLOBALS array may be more suitable.
I think I understand.
Reply With Quote
  #16  
Old 10-27-2004, 05:44 AM
Natch's Avatar
Natch Natch is offline
 
Join Date: Nov 2002
Location: Australia
Posts: 851
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Ocean
I think I understand.
If I can clarify in more detail, or give you seom more detailed examples of where I have/would use global variables and where I have/would return values, just PM me and I can give you a look at some of the apps I've written...
Reply With Quote
  #17  
Old 10-27-2004, 10:04 PM
Ocean's Avatar
Ocean Ocean is offline
 
Join Date: Mar 2004
Posts: 208
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Natch

If I can clarify in more detail, or give you seom more detailed examples of where I have/would use global variables and where I have/would return values, just PM me and I can give you a look at some of the apps I've written...
Thanks, Natch. I truly appreciate your help, as well as the help offered by everyone else.


Thanks, all!
Reply With Quote
Reply


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 11:25 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.04203 seconds
  • Memory Usage 2,242KB
  • Queries Executed 11 (?)
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
  • (5)bbcode_php
  • (6)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
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)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_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