Page 1 of 1

autoload

Posted: Mon Jan 24, 2011 8:36 am
by jason87dk
Hi,

I've checked out most of the __autoload posts here, but I don't find my following their guidelines resulting in my own script working.

So, anyways, I have my site structured into two different folders, 'sys' & 'public' (same hierarchal level). I have a subdomain pointing to 'public' (I'm not allowed in httpd.conf, I know the root remains unchanged) in which 'index.php' resides:

Code: Select all

include_once '../sys/core/init.inc.php';
$engine = new Engine(true);
init.inc.php looks like this:

Code: Select all

session_start();

/*
 * Generate token
 */
if(!isset($_SESSION['token'])) {
	$_SESSION['token'] = sha1(uniqid(mt_rand(), TRUE));
}

include_once '../sys/config/db-cred.inc.php'; // Working

foreach($C as $name => $val) {
	define($name, $val); // Working, refers to db-cred
}

function __autoload($class) {
	$filename = '../sys/class/class.'.$class.'.inc.php'; // FYI i've tried every possible combination of ../ and so forth
	if(file_exists($filename)) {
		include_once $filename;
	}
}
I get the following when requesting 'index.php':
[text]Fatal error: Class 'Engine' not found in /customers/somedomain.de/somedomain.de/httpd.www/public/index.php on line 3[/text]
Line 3 being the 'new Engine(true)' part..

The Engine class does not extend any other class but does, however, have its own __autoload and creates instances of other classes as well as requesting static methods from some of them.

It's working perfectly on my MAMP setup, which gives me some sense of 'it can't be all wrong', but what do I know.

I've exhausted my simple mind in a vain attempt to understand the situation, I'm hoping to get maybe a poke in the right direction..
Any help will be greatly appreciated,

A Dane in despair..

Re: autoload

Posted: Mon Jan 24, 2011 2:00 pm
by AbraCadaver
There is a file named class.Engine.inc.php in the /customers/somedomain.de/somedomain.de/httpd.www/sys/class/ directory?

Just a hunch, but maybe use:

Code: Select all

$filename = '../sys/class/class.'.strtolower($class).'.inc.php';

Re: autoload

Posted: Mon Jan 24, 2011 2:14 pm
by John Cartwright
AbraCadaver wrote:There is a file named class.Engine.inc.php in the /customers/somedomain.de/somedomain.de/httpd.www/sys/class/ directory?

Just a hunch, but maybe use:

Code: Select all

$filename = '../sys/class/class.'.strtolower($class).'.inc.php';
Coming from a MAMP setup, I would have thought case-sensitivty wouldn't be an issue (since Mac filenames are already case sensitive).

Re: autoload

Posted: Mon Jan 24, 2011 2:31 pm
by jason87dk
Thanks for the replies. I actually tried the strtolower() before, didn't make any difference.

EDIT [two minutes later]
So I tried the strtolower again, and, it worked.. I must have tried it while messing with the relative paths. Thank you!