Re: $GLOBALS problem
| From: | Andrey Hristov | Date: | Tue, 06 Aug 2002 13:47:48 +0000 |
| Subject: | Re: $GLOBALS problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-111372@lists.php.net to get a copy of this message | ||
The following code does not give any error messages:
<?php
error_reporting(E_ALL);
$journal_month = array("", "January", "February", "March",
"April", "May",
"June", "July", "August", "September", "October",
"November", "December");
journal_convertDate();
function journal_convertDate($date=''){
$months = $GLOBALS["journal_month"];
var_dump($months);
}
?>
Output:
array(13) { [0]=> string(0) "" [1]=> string(7) "January" [2]=>
string(8)
"February" [3]=> string(5) "March" [4]=> string(5) "April"
[5]=> string(3)
"May" [6]=> string(4) "June" [7]=> string(4) "July" [8]=>
string(6) "August"
[9]=> string(9) "September" [10]=> string(7) "October" [11]=> string(8)
"November" [12]=> string(8) "December" }
Regards,
Andrey
P.S.
PHP 4.1.1/ win32
----- Original Message -----
From: "Andy Tawse" <andy.t@newmediacollective.com>
To: <ahristov@icygen.com>
Sent: Tuesday, August 06, 2002 4:42 PM
Subject: Re: [PHP] $GLOBALS problem
> $journal_month = array("", "January", "February",
> "March", "April", "May",
"June", "July", "August", "September", "October",
"November", "December");
>
> ...
>
> function journal_convertDate($date){
>
> $months = $GLOBALS["journal_month"];
>
> ...
> }
>
>
> and the error message I get:
>
> Notice: Undefined index: journal_month in c:\andyt\inc\modules\Journal.php
on line 375
>
>
> When i use
>
> function journal_convertDate($date){
>
> global $journal_month;
>
>
> it works.
>
>
>
> On Tue, 6 Aug 2002 16:34:21 +0300, you wrote in php.general:
> > Could you paste few lines of code that shows this problem as well as
output
> > from the browser.
> >
> > Thanks.
> >
> > Regards,
> > Andrey
> >
> > ----- Original Message -----
> > From: "Andy Tawse" <andy.t@newmediacollective.com>
> > To: <php-general@lists.php.net>
> > Sent: Tuesday, August 06, 2002 4:17 PM
> > Subject: [PHP] $GLOBALS problem
> >
> >
> > > hello all.
> > >
> > > I'm having a very strange problem involving the $GLOBALS array. I
have a
> > global variable defined called $journal_month and I've been trying to
access
> > it from inside a function like so:
> > >
> > > $months = $GLOBALS["journal_month"];
> > >
> > > but I was getting an 'undefined index' error. The variable dump
confirmed
> > that PHP didnt think there was a global variable called journal_month. I
> > have used $GLOBALS countless other times in the
> > > script with no problems and have actually been able to refer to
> > $GLOBALS["journal_month"] from a different function. So I tried:
> > >
> > > global $journal_month;
> > >
> > > and it worked!?
> > >
> > > I didnt think there was any difference between the $GLOBALs array and
> > using the global statement.
> > >
> > > The variable is an array and is defined near the top of the script.
This
> > script is 'require'd by the main one.
> > >
> > > I'm running Win2000 and PHP 4.2.1 as an Apache module.
> > >
> > > Thanks for any help
> > >
> > > Andy.
> > >
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> > >
> >
>
>
>
>
>