Using $GLOBALS in a function within a class

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bnisperos
Forum Newbie
Posts: 2
Joined: Wed Oct 09, 2002 6:23 pm

Using $GLOBALS in a function within a class

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
bnisperos
Forum Newbie
Posts: 2
Joined: Wed Oct 09, 2002 6:23 pm

Post 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?
Post Reply