Re: [SMARTY] Re: global vars in templates

From: Date: Mon, 15 Apr 2002 14:34:11 +0000
Subject: Re: [SMARTY] Re: global vars in templates
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-3731@lists.php.net to get a copy of this message
When you created the $a variable, you were not in global scope (just in the scope of the current Smarty template.) You could do this: $GLOBALS['a'] = 'foo'; myfunc() {
    echo $GLOBALS['a'];
} Then you know your variable is always in global scope. Norbert Röcher wrote:
"Eric" <eric@themepark.com> schrieb:
The variable $a is not carried down into the function test_a, even
though I
use the 'global' command. (It works fine, of course, if I just
include the
file in PHP file for the page, instead of trying to have the template
do the
include.) Why does this happen? Does it have something to do with variable
scoping
around classes?
Yes. This should work like you expect: <?php global $a; $a = 123; test_a(); function test_a() { global $a; if ($a == 123) { echo "yeah it works!"; } else { echo "no luck-- bummer dude"; } } ?> Regards, Norbert
-- Monte Ohrt <monte@ispi.net> Director of Technology, ispi Inc.

« previous php.smarty.general (#3731) next »