Globals funkiness
| From: | Boget, Chris | Date: | Tue, 16 Oct 2001 20:19:18 +0000 |
| Subject: | Globals funkiness | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-71256@lists.php.net to get a copy of this message | ||
Consider (and run) the following code:
function globalize() {
global $STATEMENT_DATE_MACRO;
global $STATEMENT_MONTH_MACRO;
global $SETTLEMENT_DATE_MACRO;
echo "$STATEMENT_DATE_MACRO = STATEMENT_DATE_MACRO<br>\n";
echo "$STATEMENT_MONTH_MACRO = STATEMENT_MONTH_MACRO<br>\n";
echo "$SETTLEMENT_DATE_MACRO = SETTLEMENT_DATE_MACRO<br>\n";
}
//function doIt() {
$today = date( "U" );
$last_month = mktime( 0, 0 , 0 , ( date( "m" ) - 1 ), 1 , date( "Y" ));
$STATEMENT_DATE_MACRO = date( "jS F, Y", $today );
$STATEMENT_MONTH_MACRO = date( "F Y", $last_month );
$SETTLEMENT_DATE_MACRO = date( "F 20, Y", $today );
globalize();
//}
//doIt();
Everything works great. Couldn't be happier. Now, uncomment the
three lines above that are commented out... the lines that start and end
the "doIt()" function and the function call itself. Run it again.
Why isn't this working? Shouldn't the calling function's variables be
part of the "global namespace" for the called functions?
Chris