Variable Scope Problem
| From: | kyle at ktyp dot com | Date: | Thu, 22 May 2003 23:12:35 +0000 |
| Subject: | Variable Scope Problem | ||
| Groups: | php.gtk.general | ||
| Request: | Send a blank email to php-gtk-general+get-3469@lists.php.net to get a copy of this message | ||
I'm working on a php-gtk Jabber client called Jabble and I've been having
trouble trying to create and update new message windows. Here is my problem
(copied from project's website):
Everytime Jabble gets a message from a new client it creates a new message
window. The name of said window is $IMWindow_usernameAThost and is created
in a "NewIMWindow()" function. So if kyle@localhost messages you, a new
window called $IMWindow_kyleATlocalhost will be created. No problem so far.
Now kyle@localhost decides to send you another message. Well when Jabble
calls its function to update window text, is checks to see if
$IMWindow_kyleATlocalhost exists. So far it is always nonexistant.
It looks like this:
function NewIMWindow($from)
{
$IMWindowname = "IMWindow".$from;
global $$IMWindowname; // Variable Variable
if(!$$IMWindowname) // if window doesn't exist
{
...create new window...
}
}
function IncomingMsgHandler($message, $from)
{
$IMWindowname = "IMWindow".$from;
global $$IMWindowname;
if(!$$IMWindowname) // THIS IS ALWAYS TRUE
{
NewIMWindow($from);
}
...update window text...
}
The problem is when the window variable is created in NewIMWindow other
functions can't seem to access it even after declaring "global".
- Kyle (kyle@ktyp.com)