Page 1 of 1

Using $GLOBALS in a function within a class

Posted: Wed Oct 09, 2002 6:23 pm
by bnisperos
Code reference from the book by wrox: Professional PHP 4:

I am trying to get the statement

$this->msg_no = $GLOBALS["msg_no"];

to work within my function which resides in a class. My error statement is the following:

Notice: Undefined index: msg_no in C:\Apache2\htdocs\_development\webmail\webmail2.php on line 46

The catch is that my server online works fine.

MY SETUP:
WORKSTATION SETUP: WAMP(win2k, apache 2.0.43, mysql, PHP 4.2.4 dev).

SERVER SETUP: FreeBSD, PHP 4.2.2


Question: Is this a linux specific statment? or is there a setting on my workstation that I need to fix?

Posted: Wed Oct 09, 2002 6:47 pm
by volka
afaik there are no settings for having $GLOBALS or not.
You're sure your script runs exactly the same way on the server and on your workstation?
try

Code: Select all

echo '<!--'; print_r($GLOBALS); echo '-->';
right before $this->msg_no = $GLOBALS["msg_no"]; and check wether the value is in the array or not.

Posted: Wed Oct 09, 2002 6:56 pm
by bnisperos
sorry about that volka... I didn't define the global on the page I was creating the class on...

but, even though the global hasn't been defined, doesn't PHP create an index anyway?