webbiz Posted March 29, 2007 Share Posted March 29, 2007 Hi, I’m having trouble creating a class instance. The code I’m using works on another server so I’m thinking it must be some settings that are wrong. The error message I get is: Fatal error: Class 'Test' not found in /mounted-storage/home30a/sub001/sc15979-ERWX/XXXdomainNameXXX/INDEX/test.php on line 6 The class include file seems to get included into the calling file OK. Example code of both the test class and calling page are bellow. I hope someone can help me out here as it is bound to be some simple setting or something. Thanks, Lance The test code I have: Class: <?php class Test{ public function __construct(){ ?> <script type="text/javascript">alert('test class');</script> <?php } } ?> Caller: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <?php include_once('http://www.THEDOMAINNAME/includes/classes-LIT/test.php'); // create class instance $testx = new Test(); ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/44735-fatal-error-class-test-not-found-in-creating-a-class-instance/ Share on other sites More sharing options...
Jenk Posted March 29, 2007 Share Posted March 29, 2007 don't use http:// use directory path. Quote Link to comment https://forums.phpfreaks.com/topic/44735-fatal-error-class-test-not-found-in-creating-a-class-instance/#findComment-217300 Share on other sites More sharing options...
webbiz Posted March 29, 2007 Author Share Posted March 29, 2007 Hi, Thanks for your reply. You are right but I was using that because I’m trying to includes files under a domain name into a file under a sub domain name. On a test page ‘../xxxx/ works but not on the main index page. I may just have to do some rethinking now that I’m on the right track. Thanks heaps. Quote Link to comment https://forums.phpfreaks.com/topic/44735-fatal-error-class-test-not-found-in-creating-a-class-instance/#findComment-217463 Share on other sites More sharing options...
redbullmarky Posted March 29, 2007 Share Posted March 29, 2007 if your problem occurs when the file is in a subdirectory but not on your main index page, then consider using something like: <?php include_once($_SERVER['DOCUMENT_ROOT'] . '/includes/classes-LIT/test.php'); ?> which is pretty much the "internal" equivalent of referencing a file from the web root. Quote Link to comment https://forums.phpfreaks.com/topic/44735-fatal-error-class-test-not-found-in-creating-a-class-instance/#findComment-217564 Share on other sites More sharing options...
Jenk Posted March 30, 2007 Share Posted March 30, 2007 Hi, Thanks for your reply. You are right but I was using that because I’m trying to includes files under a domain name into a file under a sub domain name. On a test page ‘../xxxx/ works but not on the main index page. I may just have to do some rethinking now that I’m on the right track. Thanks heaps. Start by noting down the directory you are currently in, then adjust includes accordingly.. echo realpath('.'); to see current working directory, then you can make a relative path accordingly. Quote Link to comment https://forums.phpfreaks.com/topic/44735-fatal-error-class-test-not-found-in-creating-a-class-instance/#findComment-218016 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.