autoload

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
jason87dk
Forum Newbie
Posts: 4
Joined: Fri Oct 30, 2009 5:29 am

autoload

Post 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..
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: autoload

Post 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';
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: autoload

Post 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).
jason87dk
Forum Newbie
Posts: 4
Joined: Fri Oct 30, 2009 5:29 am

Re: autoload

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