Page 1 of 1

Not able to find the class.

Posted: Fri Nov 09, 2007 6:24 am
by Andromeda
I have a problem with a class that i just not can figure out.
for some reason it won't load a global variabel in a class :(

index.php

Code: Select all

require_once(PATH_MODULE."news/class.paging.php");
	require_once(PATH_MODULE."news/class.news.php");
	
	$pg = new paging(2);
	var_dump($pg);
	$nw = new news();
The class.news.php

Code: Select all

class news {
	public function news()
	{
		global $pg;
		// This list an array of the news to an $this-> var
		var_dump($pg);
	}
}
This outputs.

Code: Select all

object(paging)#5 (4) { ["limit"]=> int(2) ["tp"]=> string(1) "8" ["pages"]=> int(0) ["menu"]=> string(0) "" }

 NULL
As you can see dose it load the class fine in the index file, but it is not able to gloalise it inside the news class. and i just don't understand why :(

Can one help me with the problem?

Posted: Fri Nov 09, 2007 8:05 am
by Zoxive
Is there a reason you can't just pass it to the class?

Code: Select all

   $pg = new paging(2);
   var_dump($pg);
   $nw = new news($pg); // Passed to Constructor

Posted: Fri Nov 09, 2007 9:04 am
by Andromeda
That is also the way i have fixed it now,
but it is only a temp fix, i would rater use it with a global

Posted: Fri Nov 09, 2007 9:26 am
by Zoxive
Is there more of a reason, than just because you want to?

http://www.google.com/search?q=php+glob ... es+are+bad