Fatal error:Class 'Test' not found - Creating Class Instance


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.


The test code I have:


<?php class Test{ public function __construct(){ ?> <?php } } ?>


<?php include_once('http://www.THEDOMAINNAME/includes/classes-LIT/test.php'); // create class instance $testx = new Test(); ?>[/php] [code] Untitled Document [/code]

** Mod Edit - Added Code and PHP tags for readabilty.


Have you tried putting the class definition in the same file as where you instantiate it? It sounds like you have problem including the file. Try including it with the http://www.domainname.com/ out of there (so make it relative).


Hi Zyppora,
Thanks for your reply.
Ok, I have just tried it by adding the class to the calling file. The good news is that it finds the class this way. The bad news is that the site can?t be built this way as the logic is to be separated and reused by a number of files.

Now the interesting thing is that if I place an alert on the top of the class file above the class, this alert is called when I include this separate file into the calling file and open the calling file. This illustrates that the file does get included but for some reason it still can?t find the class.

MMmmm, just did another test by removing the domain name from the include string as you were hinting to and it worked. This is a problem as I need to access classes from sub domain files and this is why I included the domain name in the include string. The class library is in a sub folder of the root under the domain name.

I?m still not sure how to solve this.


I’m afraid you’re going to have to include it using a relative path (so not the http://blabla in front of it), as include() DOES do this correctly at times, but cannot be guaranteed. If you include a file from the internet (http://blabla/file.php) the remote server parses the PHP and only sends the output (ie. the HTML and JavaScript that it outputs). For more info, see Includes.


Backing out of the folder that has the sub domain files by going ?../xxxx? works on a test page but not the all important index page of that folder. I?m getting closer now that I?m on the right track. I may have to do some rethinking.

Thanks heaps.