Not able to find the 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
Andromeda
Forum Newbie
Posts: 11
Joined: Thu Nov 08, 2007 5:40 am

Not able to find the class.

Post 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?
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post 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
Andromeda
Forum Newbie
Posts: 11
Joined: Thu Nov 08, 2007 5:40 am

Post 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
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

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