Re: global vars in templates
| From: | Norbert Röcher | Date: | Sun, 14 Apr 2002 22:34:33 +0000 |
| Subject: | Re: global vars in templates | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-3715@lists.php.net to get a copy of this message | ||
"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