Troubles Accessing Global Variables
| From: | Adelaide Yip | Date: | Sun, 18 Jan 2004 04:49:01 +0000 |
| Subject: | Troubles Accessing Global Variables | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-174954@lists.php.net to get a copy of this message | ||
> Hi,
>
> I'm having troubles accessing the global variables. From my understanding
> of PHP, when you declare a variable 'global' it is no longer just in the
> local scope, but becomes known in the global scope of the program.
>
> In file, 'layout.php' ...
> function top_sidebar_header() {
> global $g_graphic;
> echo $g_graphic;
> }
>
> In file, 'body.php' ...
> include_once( $GLOBALS["DOCUMENT_ROOT"] . "/include/layout.php" );
> top_sidebar_header(); // function is called, but when "echo
> $g_graphic" is executed,
> // nothing prints out because
> $g_graphic is empty or ""
>
> In file, 'about/index.php' ...
> $g_graphic = "/media/image.jpg";
> include_once( $GLOBALS["DOCUMENT_ROOT"] . "/body.php" );
>
> Have I overlooked something crucial?
>
> I haven't been able to find much documentation on this topic. (Please
keep
> in mind that I am also a newbie at PHP. :) ) ~ It'd be really great if
any
> of you have suggestions on this.
>
> Thanks in advance,
> Adelaide
>