Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

smarty kills global variables?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
luke2000
Smarty Rookie


Joined: 29 Mar 2004
Posts: 13

PostPosted: Mon May 24, 2004 2:56 pm    Post subject: smarty kills global variables? Reply with quote

hi, i'm guessing that if you do a
smarty->display("index.tpl");
global variables are "lost"
cause i wrote a gallery (works fine with normal php)
now, i turn it into templated version
now stops working, (not the only one, also other scripts don't work anymore)

any way to change that?
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon May 24, 2004 4:02 pm    Post subject: Reply with quote

no global variables are "lost".
they are just invisible inside functions and methods in php like the display() method of $smarty.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
luke2000
Smarty Rookie


Joined: 29 Mar 2004
Posts: 13

PostPosted: Mon May 24, 2004 4:03 pm    Post subject: Reply with quote

well.. have to find a workaround then Wink

Luke
Back to top
View user's profile Send private message
hucky
Smarty Rookie


Joined: 02 Sep 2004
Posts: 6

PostPosted: Tue Sep 07, 2004 8:56 pm    Post subject: hei Reply with quote

Quote:
hey are just invisible inside functions and methods in php like the display() method of $smarty.


??? can you give me an example how i can use this global variables?
and how invisible?

thx[/quote]
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Tue Sep 07, 2004 11:06 pm    Post subject: Reply with quote

Sure, use either:

1) declare your intention to use a global var

global $var; // $var is now a reference to the global $var
$foo = $var;

or:

2) reference the superglobal (which is always in-scope):

$foo = $GLOBALS['var'];

More at the PHP manual:
http://php.net/language.variables.scope
http://php.net/reserved.variables

IMHO, globals suck. I usually get around it by having a static class that has functions that hold static vars to store data. With a little bit of thought you can can implement a class that organizes and unifies access to all of your shared data (static data, shared objects, singletons, etc)
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP