Page 1 of 1

problem with a class

Posted: Sat May 24, 2003 9:21 pm
by Little Spy
i have a class for my html template, in there is a function like this

Code: Select all

// Other file
$online_string = "1,2,3,4,5,6";
etc.....


<?php

function CreatePage() {

		if ($GLOBALS[online_string]) {
		       $this->SetParameter("online_string", $online_string);
		       $this->SetParameter("online_list", $online_list);
		       $this->SetParameter("online_guests", $guests_online);
		       $this->SetParameter("online_total", $totalonline);

	}
?>
the $online_string, $online_list variables are in a file included before the class. How can I use those variables in the class because what i have now fails, anyone have any idea how I can make this work, i tried using $GLOBALS first btw but it doesnt work.

Posted: Sat May 24, 2003 9:38 pm
by evilcoder
is the other file and extension of that class, or does it just have plain old variables in it. Coz if thats the case, just include the file and use the variables like that.

Posted: Sat May 24, 2003 9:45 pm
by Little Spy
it just has variables in it, i am sure what you mean by just include them

Posted: Sat May 24, 2003 9:49 pm
by evilcoder

Code: Select all

<?php

function CreatePage() { 
      include( "filewithvariabes.php" );

      if ($GLOBALS[online_string]) { 
             $this->SetParameter("online_string", $online_string); 
             $this->SetParameter("online_list", $online_list); 
             $this->SetParameter("online_guests", $guests_online); 
             $this->SetParameter("online_total", $totalonline); 

   } 
?>
thats how. :)

Posted: Sun May 25, 2003 6:11 am
by volka
Little Spy wrote:the $online_string, $online_list variables are in a file included before the class
evilcoder wrote:function CreatePage() {
include( "filewithvariabes.php" );
so this file is included twice now. I doubt that's exactly what Little Spy wants.
You check for an entry in $GLOABLS (which is superglobal) but then you use the plain variables (like $online_string) that are bound to the scope of the function. why?

Code: Select all

function CreatePage() {
	if ($GLOBALS['online_string']) {
		$this->SetParameter("online_string", $GLOBALS['online_string']);
		$this->SetParameter("online_list", $GLOBALS['online_list']);
		$this->SetParameter("online_guests", $GLOBALS['guests_online']);
		$this->SetParameter("online_total", $GLOBALS['totalonline']);
	}
}