problem with 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
Little Spy
Forum Commoner
Posts: 31
Joined: Thu Oct 10, 2002 8:18 pm
Contact:

problem with a class

Post 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.
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post 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.
Little Spy
Forum Commoner
Posts: 31
Joined: Thu Oct 10, 2002 8:18 pm
Contact:

Post by Little Spy »

it just has variables in it, i am sure what you mean by just include them
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

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

Post 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']);
	}
}
Post Reply