I have 2 files: master.php and test.php. master.php has a class in it that I would like to include in test.php. The only problem is that test.php is ignoring the class in master.php.

Here is the code:

Test.php:

include("http://".$_SERVER['HTTP_HOST']."/rebuild/scripts/php/master.php");
$loader = new modLoader();
$module[0] = 'm.class.templating.php';
$module[1] = 'm.class.userInfo.php';
$loader->modules = $module;
$loader->loadUp();

master.php:

class modLoader
	{
		public $modules = array();
		
		function loadUp()
			{
				include('http://'.$_SERVER['HTTP_HOST'].'/rebuild/scripts/php/classes.php');
				
				foreach($this->modules as $key=>$value)
					{
						include('http://'.$_SERVER['HTTP_HOST'].'/rebuild/scripts/php/modules/'.$value);
					}
			}
	}

Here is the error I get:
Fatal error: Class 'modLoader' not found in /var/www/html/rebuild/test.php on line 3

I've even tried having the include file master.php echo some stuff and that works fine. Just no class. Anyone have any ideas?

Recommended Answers

All 2 Replies

I have, unfortunately, no experience with OOP, and can't make sense of OOP code, but this sounds like a scope issue to me.

You've established that the master.php code is being referenced. That would have been my first piece of advice.

How about if you put your echo test statement inside the class? Does it work outside the class but fail inside? If so, and it was a function displaying that behavior, the culprit would be scope and it could be fixed with a simple global $myvar; statement.

Could that fix your problem?

(I've taken courses, and understand the basic OOP concepts, but can't see how to actually apply it to my PHP projects. Too bad, enough people embrace it that I know it must be worthwhile. Some day maybe.)

Blah! Nevermind, I found out that it was because I was including the full non relative path.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.