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:


$loader = new modLoader();
$module[0] = 'm.class.templating.php';
$module[1] = 'm.class.userInfo.php';
$loader->modules = $module;


class modLoader
		public $modules = array();
		function loadUp()
				foreach($this->modules as $key=>$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?

7 Years
Discussion Span
Last Post by xylude

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.